0
点赞
收藏
分享

微信扫一扫

vue解决img动态src问题(相对路径)

泠之屋 2022-02-26 阅读 93

template:

<div v-for="item in imgList" class="single-img">
  <img
   :key="item.imgNo"
   draggable="false"
   :src="require(item.src + '')"
   :width="item.width + 'px'"
   :height="item.height + 'px'"
   alt=""
  />
</div>

script:

this.imgList = [
    {
      imgNo: 1,
      src: './img/1g.png',
      width: 40,
      height: 40
    }, {
      imgNo: 2,
      src: './img/2g.png',
      width: 40,
      height: 40
    }
]

就是这么简单,在后面加一对引号:require(item.src + '')。原理我也不太清楚,有知道的说一下,大家学习。

举报

相关推荐

0 条评论