0
点赞
收藏
分享

微信扫一扫

vue项目中img的src动态赋值


没想到这破东西,居然这么折腾人。

时间紧,长话短说。一般这个动态赋值,要用require。而且,这个require里,只能有一个变量,多个变量,有运算,有方法,都不行。

1、不行

<img
:src="require(`@/${state.path + photo.name}`)"
:alt="photo.text"
/>

2、不行

<img
:src="require(getPath(photo))"
:alt="photo.text"
/>

3、可以

<img
:src="require(`@/modules/assets/images/home/temp/${photo.name}`)"
:alt="photo.text"
/>


举报

相关推荐

0 条评论