<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>
