useImage.js 734 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * 이미지 URL 헬퍼 composable
  3. */
  4. export const useImage = () => {
  5. const config = useRuntimeConfig()
  6. /**
  7. * 이미지 상대 경로를 절대 URL로 변환
  8. * @param {string} path - 이미지 상대 경로 (예: "/uploads/images/abc.jpg")
  9. * @returns {string} - 전체 URL (예: "http://gojinaudi.mycafe24.com/uploads/images/abc.jpg")
  10. */
  11. const getImageUrl = (path) => {
  12. if (!path) return ''
  13. // 이미 전체 URL인 경우 그대로 반환
  14. if (path.startsWith('http://') || path.startsWith('https://')) {
  15. return path
  16. }
  17. // 상대 경로인 경우 imageBase 붙이기
  18. const imageBase = config.public.imageBase
  19. return `${imageBase}${path}`
  20. }
  21. return {
  22. getImageUrl
  23. }
  24. }