遍历循环多条数组对象
JSON数据:
[
{img: /5bbb465d-4dd2-4b14-9fa8-b48aaad95221/qq05.png"
id: 1
spiritName: "数据1"
url: "https://www.baidu.com/"
},
{
img: /5bbb465d-4dd2-4b14-9fa8-b48aaad95221/qq06.png"
id: 2
spiritName: "数据2"
url: "https://www.baidu.com/"
}]
JS:
export default {
name: "",
data() {
return {
imgArray:[],
};
get(){
let that = this
list().then(responsr =>{
let val = response.data
val.forEach(function(value){
let imgObject = {
img:value.img,
url:value.url
}
that.imgArray.push(imgObject)
})
})
}
},
vue:
<el-carousel class="swiper-container":interval="5000" type="card" >
<el-carousel-item v-for="item in imgArray" :key="item.id">
<a :href=item.url>
<div class="swiper-slides">
<img class="swiper-slide-img" :src=item.img alt="">
</div>
</a>
</el-carousel-item>
</el-carousel>
本文来自博客园,作者:小基狠努力啊,转载请注明原文链接:https://www.cnblogs.com/ylh188/p/14988067.html