b7addb5c7a
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
22 lines
520 B
Vue
22 lines
520 B
Vue
<script setup lang="ts">
|
|
const props = defineProps<{
|
|
src?: string
|
|
alt?: string
|
|
}>()
|
|
|
|
const route = useRoute()
|
|
|
|
const resolvedSrc = computed(() => {
|
|
if (!props.src) return ''
|
|
// 绝对路径直接用
|
|
if (props.src.startsWith('/') || props.src.startsWith('http')) return props.src
|
|
// 相对路径:基于当前路由拼接
|
|
const base = route.path.replace(/\/$/, '')
|
|
return `${base}/${props.src}`
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<img :src="resolvedSrc" :alt="alt" loading="lazy" decoding="async" />
|
|
</template>
|