:src动态导入图片路径

对于webpack

1
const img = require(`./img/${name}.png`)
1
<img :src="img" />

或者直接在html中使用

1
2
<img :src="require(`./img/${name}.png`)" />
<img :src="require(`@/img/${name}.png`)" />

对于vite

1
2
// ..
activeIcon: new URL('@/assets/icon/intelligent-contro.png', import.meta.url).href,
1
2
3
4
5
<img
:src="item.activeIcon"
height="40"
alt=""
>