vite 動態(tài)引入圖片的時候會報錯, require is not defined
網(wǎng)上很多推薦的是寫法是配置vite-plugin-require-transform
但是這個不是穩(wěn)定,我安裝配置后一直報錯
[vite] Internal server error: This experimental syntax requires enabling one of the following parser plugin(s): "jsx", "flow", "typescript". (1:0)

image.png
去插件githu查看issue,暫無法解決

image.png
放棄了,不再掙扎了。
替換成下面的方法進(jìn)行引入
1.new URL
const loadingName = (name) => {
return new URL(`../src/assets/${name}.svg`, import.meta.url).href;
};
<img alt="Vue logo" class="logo" :src="url2" width="125" height="125" />
2.import
const loading = async (name) => {
const src = await import(`/src/assets/${name}.svg`);
url.value = src.default;
return src.default;
};
<img
alt="Vue logo"
class="logo"
:src="loading('logo')"
width="125"
height="125"
/>