vue图片src动态拼接

<img :src="getImgUrl(item)" v-for="(item,index) of imgList" :key="index" />

<script>
const imgList=[1,2,3,4,5,6,7,8]
data(){
    return{
        imgList,
    }
}
getImgUrl(i){
    return require("../../assets/tourpic/picture"+i+".jpg")
}
</script>



或者



<img :src="require('../../assets/tourpic/picture'+item+'.jpg')" v-for="(item,index) of imgList" :key="index" />

<script>
const imgList=[1,2,3,4,5,6,7,8]
data(){
    return{
        imgList,
    }
}
</script>
posted @ 2020-01-15 15:23  huihuihero  阅读(4541)  评论(0编辑  收藏  举报