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

posted on 2022-10-31 17:36  左直拳  阅读(1)  评论(0)    收藏  举报  来源

导航