第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

VueJS 根據(jù) for 循環(huán)中的變量加載 SVG 文件,使用 v-html 給出

VueJS 根據(jù) for 循環(huán)中的變量加載 SVG 文件,使用 v-html 給出

倚天杖 2023-10-04 15:09:31
我正在嘗試根據(jù)循環(huán)中的內(nèi)容加載保存在單獨(dú)文件中的 SVG。當(dāng)頁(yè)面加載時(shí),我看到這個(gè):嘿,這是我的代碼:<div  v-for="(rec, index) in stats"  :key="index">    <div class="iconForeground align-self-center" v-html="require(`../../../assets/svg/dashboard/attributes/${rec.icon}.svg`)">    </div></div>這是數(shù)據(jù)函數(shù),為了簡(jiǎn)潔起見,我省略了整個(gè)內(nèi)容:data() {  return {    stats: [{name: "Leadership", percent: "75", top: "5", icon: "leadership"},             {name: "Innovation", percent: "25", icon: "genius-ideas"}] as Array<Record<string, string>>  }}我怎樣才能做到這一點(diǎn)?編輯 這是我的 vue.config.js:const path = require("path");module.exports = {  pluginOptions: {    'style-resources-loader': {      preProcessor: 'scss',      patterns: [        "./src/styles/global.scss"      ]    },    configureWebpack: {      module: {        rules: [{          test: /\.svg$/,          loader: 'vue-svg-loader'        }]      }    }  }}編輯2似乎即使在安裝 url-loader 并遵循建議之后,我仍然無(wú)法加載圖像,這是我更新的 vue.config.js:const path = require("path");module.exports = {  pluginOptions: {    'style-resources-loader': {      preProcessor: 'scss',      patterns: [        "./src/styles/global.scss"      ]    },    configureWebpack: {      module: {        rules: [        {          test: /\.svg$/,          loader: 'vue-svg-loader'        },        {          test: /\.(png|jpg|gif)$/i,          use: [            {              loader: 'url-loader',              options: {                esModule: false,              },            },          ],        }]      }    }  }}和我的html:<div class="d-flex flex-column justify-content-center" :style="{marginRight: '24px'}">    <div class="purpleDot"></div>    <div class="iconForeground align-self-center">       <img :src="require(`../../../assets/svg/dashboard/attributes/${rec.icon}.svg`)" />    </div></div>
查看完整描述

2 回答

?
GCT1015

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超4個(gè)贊

答案是使用像這樣的動(dòng)態(tài)組件

<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>>

? }

}


查看完整回答
反對(duì) 回復(fù) 2023-10-04
?
蝴蝶不菲

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊

刪除你的 svg 加載器


   {

          test: /\.svg$/,

          loader: 'vue-svg-loader'

        },

將 svg 添加到您的 url-loader


  test: /\.(png|jpg|gif|svg)$/i,

          use: [

            {

              loader: 'url-loader',

              options: {

                esModule: false,

              },

            },

          ],

        }

這通常是因?yàn)槟愕?webpack 加載器設(shè)置


嘗試將esModule選項(xiàng)設(shè)置url-loader為false。


這應(yīng)該可以解決你的問(wèn)題。


您無(wú)需關(guān)注以下內(nèi)容。


還有一個(gè)問(wèn)題,即使你修復(fù)了加載器,你仍然無(wú)法加載它。


對(duì)于圖像,您應(yīng)該使用img標(biāo)簽來(lái)加載它。


<img :src=`require(...)`/>

v-html只會(huì)加載它的路徑字符串。


查看完整回答
反對(duì) 回復(fù) 2023-10-04
  • 2 回答
  • 0 關(guān)注
  • 270 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)