Answer the question
In order to leave comments, you need to log in
How to get data with axios from all api pages?
What am I doing wrong? I want to get data from all pages in api. I think the while is the problem, but I don't know how to run the page loop any other way!
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()));
},
Answer the question
In order to leave comments, you need to log in
1) Stopped working what?
Guess:
2) "axios await async habr qna" in the search engine, there are links here on how then works . Asynchrony. The command seems to be completed, and the value will be later.
Promises annoy me a little))), but it's interesting to puzzle with them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question