2 回答

TA貢獻1827條經驗 獲得超4個贊
答案是使用像這樣的動態組件
<template>
? div
? ? v-for="(m, i) in modules"
? ? :key="i">
? ? <component :is="m.image"></component>
? </div>
</template>
import PraiseIcon from "@/assets/svg/navigation-bar/Praise-Icon.svg";
components: {
? 'Praise-Icon': PraiseIcon
},
data() {
? return {
? ? modules: [
? ? ? ? {
? ? ? ? ? name: "Praise",
? ? ? ? ? image: "Praise-Icon",
? ? ? ? }
? ? ? ] as Array<Record<string, string>>
? }
}

TA貢獻1810條經驗 獲得超4個贊
刪除你的 svg 加載器
{
test: /\.svg$/,
loader: 'vue-svg-loader'
},
將 svg 添加到您的 url-loader
test: /\.(png|jpg|gif|svg)$/i,
use: [
{
loader: 'url-loader',
options: {
esModule: false,
},
},
],
}
這通常是因為你的 webpack 加載器設置
嘗試將esModule選項設置url-loader為false。
這應該可以解決你的問題。
您無需關注以下內容。
還有一個問題,即使你修復了加載器,你仍然無法加載它。
對于圖像,您應該使用img標簽來加載它。
<img :src=`require(...)`/>
v-html只會加載它的路徑字符串。
- 2 回答
- 0 關注
- 272 瀏覽
添加回答
舉報