如何在 catch 上终止函数执行?我认为 return 应该放在我放置的位置 (.catch( error => {console.log(error);} return)
),但这不起作用。告诉我怎样做才是正确的?
getCustomers: function () {
let url = '/crm/customer/';
axios.get(url).then((response) => {
this.customers = response.data.results;
if (this.customers.length === 100) {
for (let i = 2; i < 100; i++) {
axios.get('/crm/customer/?page=' + i).then((response) => {
this.c = response.data.results;
for (let item of this.c.values()) {
this.customers.push(item);
}
}).catch( global_waiting_stop());
}
}
}).catch( error => { console.log(error); })
.finally(() => (global_waiting_stop()));
},
最佳答案
finally()
在then
之后执行和 catch
功能。如果您不想让它运行,请移动您的 global_waiting_stop
到底部then
相反,阻止并摆脱 finally
.
getCustomers: function() {
let url = '/crm/customer/';
axios.get(url).then((response) => {
this.customers = response.data.results;
if (this.customers.length === 100) {
for (let i = 2; i < 100; i++) {
axios.get('/crm/customer/?page=' + i).then((response) => {
this.c = response.data.results;
for (let item of this.c.values()) {
this.customers.push(item);
}
}).catch(error => {
console.log(error);
}
return)
.finally(() => (global_waiting_stop()));
}
}
global_waiting_stop();
}).catch(error => {
console.log(error);
})
},
关于javascript - 如何在catch上终止函数执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63634333/