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 + '')
。原理我也不太清楚,有知道的说一下,大家学习。