需要利用import引入图片,这样就能动态设置。具体代码如下
<script setup>
import { onMounted, ref } from "vue";
import imgname from "../assets/logo.png"; //引入
const imsstr = ref("")
onMounted(()=>{
imsstr.value = imgname; //设置值
})
</script>
<template>
<div class="greetings">
<h1 class="green">test</h1>
<img :src="imsstr" alt="">
</div>
</template>