最近在写vue的项目,由于后台返回的数据量太大,致使页面卡死直接蹦掉了,而后后台小哥哥和我讲能够分批处理~没想到真的是快了不少不少,眼过千变不如手过一遍~,在此记录一下!!! 首先咱们要定义两个变量:
vue
data() { page: 0, number: 1 }ios
getData(){
this.$axios.post("/api/XXX", {}).then(res=>{
if (res.data.rows) {
let inquiryRelates = res.data.rows.InquiryRelates;
if (inquiryRelates.length < 5) {
this.InquiryRelates = inquiryRelates;
this.loadData = false;
} else {
this.lazyLoadCount(this.page, this.number, inquiryRelates);
}
}
})
}
lazyLoadCount(page, number, inquiryRelates) {
this.InquiryRelates = this.InquiryRelates.concat(inquiryRelates.slice(page, number));
if (this.InquiryRelates.length < inquiryRelates.length) {
setTimeout(() => {
this.page += 1;
this.number += 1;
this.lazyLoadCount(this.page, this.number, inquiryRelates);
}, 1000);
} else {
this.loadData = false;
}
},
复制代码
}axios