1. 方法一
原先结构
改成结构
initAxios(url) {
this.$axios.get(url).then((response) => {
let json = response.data.Data //获取到的数据
let show = json;
var groupSize = 13; //每页显示13个数据
var newgroup = [];
var tempGroup = [];
let currentIndex=0
show.forEach(item => {
tempGroup.push(item);
if (tempGroup.length === groupSize) {
newgroup.push(tempGroup)
tempGroup = []
}
});
if (tempGroup.length > 0) {
newgroup.push(tempGroup);
}
//上面是把数组分成 [[],[],[]] 这样的结构,如图所示
this.listData=newgroup[currentIndex]
this.b=setInterval(()=>{
currentIndex = (currentIndex + 1) % newgroup.length;
this.listData=newgroup[currentIndex]
},10*1000)
})
},
2. 方法二
// 列表
common.ajaxTwo('Get','url').then(res=>{
if(res.Code==0){
this.listData=res.Data1
this.indexOne=0
this.singleShow()
}
})
change(num) {
this.showListData = [];
let index = 0;
if (this.indexOne === this.listData.length) {
this.indexOne = 0;
}
for (let i = this.indexOne; i < this.indexOne + num; i++) {
if (this.listData[i]) {
this.showListData.push(this.listData[i]);
index = i;
}
}
this.indexOne = index + 1;
},
singleShow() {
this.change(5)
// 单纯展示
this.a = setInterval(() => {
this.change(5)
}, 5000)
},