【发布时间】:2020-12-17 14:39:34
【问题描述】:
我做错了什么?我想从api中的所有页面获取数据。添加while后它停止工作,但我不知道如何以不同的方式启动页面循环!
getCustomers: function() {
let url = '/crm/customer/';
return axios.get(url).then((response) => {
this.customers = response.data.results;
if (this.customers.length === 100) {
let i = 2;
axios.get('/crm/customer/?page=' + i).then((response) => {
this.c = response.data.results;
i += 1;
for (let item of this.c.values()) {
this.customers.push(item);
}
while (this.c.length === 100) {
axios.get('/crm/customer/?page=' + i).then((response) => {
this.c = response.data.results;
i += 1;
for (let item of this.c.values()) {
this.customers.push(item);
}
}).catch( error => {}).finally(() => (global_waiting_stop()));
}
}).catch( error => {}).finally(() => (global_waiting_stop()));
}
}).catch( error => {}).finally(() => (global_waiting_stop()));
},
【问题讨论】:
-
while是一个无限循环,因为您将异步代码与同步代码混淆了 -
@TKoL 请告诉我,我该怎么做才能更好?我是初学者
标签: javascript api vue.js axios