28 lines
678 B
Vue
28 lines
678 B
Vue
<template>
|
|
<img :src="imageSrc" :alt="alt" v-bind="$attrs" />
|
|
</template>
|
|
|
|
<script setup>
|
|
import { computed } from 'vue'
|
|
|
|
const props = defineProps({
|
|
src: {
|
|
type: String,
|
|
required: true
|
|
},
|
|
alt: {
|
|
type: String,
|
|
default: ''
|
|
}
|
|
})
|
|
|
|
// 使用 Vite 的 import.meta.glob 或简单字符串拼接
|
|
// 由于别名在运行时不可直接动态拼接,我们这里使用一个更稳妥的方法
|
|
// 映射到我们配置好的别名
|
|
const imageSrc = computed(() => {
|
|
// 处理路径,确保指向别名
|
|
const path = props.src.startsWith('/') ? props.src.slice(1) : props.src
|
|
return new URL(`../../../resources/${path}`, import.meta.url).href
|
|
})
|
|
</script>
|