fix. img 컴포넌트 수정

This commit is contained in:
clkim
2025-10-30 21:42:19 +09:00
parent 8229550220
commit e9a9299a4a
3 changed files with 23 additions and 24 deletions

View File

@@ -0,0 +1,41 @@
<script setup lang="ts">
import { getResolvedHost } from '#layers/utils/styleUtil'
import type { PageDataResourceGroup } from '#layers/types/api/pageData'
interface Props {
resourcesData?: PageDataResourceGroup
objectFit?: 'contain' | 'cover'
alt?: string
}
const props = withDefaults(defineProps<Props>(), {
objectFit: 'contain',
alt: 'image',
})
const imagePaths = computed(() => {
if (!props.resourcesData?.res_path) return null
const pc =
props.resourcesData.res_path.path_pc ?? props.resourcesData.res_path.path_mo
const mo =
props.resourcesData.res_path.path_mo ?? props.resourcesData.res_path.path_pc
return {
pc: pc ? getResolvedHost(pc) : '',
mo: mo ? getResolvedHost(mo) : '',
}
})
</script>
<template>
<picture v-if="imagePaths" ref="pictureRef">
<source media="(min-width: 1024px)" :srcset="imagePaths.pc" />
<source media="(max-width: 1023px)" :srcset="imagePaths.mo" />
<img
:src="imagePaths.pc"
:alt="alt"
:class="`w-full h-full object-${objectFit}`"
loading="lazy"
/>
</picture>
</template>