vue3 ts中拼接本地图片地址
当我们在vue3中使用本地的图片地址,该地址又是以:src="地址"这种方式使用时,不能直接该图片的地址,而是要用vite提供的图片引用方式
new Url('图片地址',import.meta.url).href
<script steup>
import { computed } from 'vue'
const imgPath = computed(() => {
return new URL('图片地址', import.meta.url).href
})
</script>
<template>
<img :src="imgPath()">
</template>
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
上次更新: 2025/09/05, 8:09:00