我試圖將 img src 屬性系結到影像路徑的變數,但沒有成功。但是,如果我復制并粘貼相同的路徑,那么它就可以了。我哪里弄錯了?
錯誤資訊:http://localhost:8080/@/assets/result-images/Soya-bean.jpg 404(未找到)
<template>
<img :src= "imgSrc" alt="No image available"/> //This doesn't work
<img src= "@/assets/result-images/Soya-bean.jpg" alt="No image available"/> //This works
</template>
<script>
import {ref} from 'vue'
export default {
setup(){
const imgSrc = ref()
imgSrc.value = "@/assets/result-images/Soya-bean.jpg"
return{imgSrc}
}
}
</script>
它在瀏覽器上的樣子
uj5u.com熱心網友回復:
imgSrc.value = require("@/assets/result-images/Soya-bean.jpg");
應該這樣做。
檔案在這里。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/465377.html
上一篇:Electron中的內置代碼錯誤:無法在“檔案”上執行“querySelector”
下一篇:快速獲取單個檔案不跳轉捕獲
