3đź‘Ť
âś…
Your Vue structure and some logic parts are incorrect:
- You should rename your
mounted
section tomethods
I think it’s typo. -
You can not call methods with way you provide in your question, place your initial request to
mounted
orcreated
hook and invoke methods onthis
:mounted() { axios.all([this.getAllTicketGroups(), this.getEventId()]) .then(axios.spread(function (list, got){ console.log(list); console.log(got); })); }
-
Also you reference some
response
variable in the top ofgetEventId
method which will always be undefined because it is not declared. -
Also you does not see anything in console after main request finished successfully because you don’t return anything in
getAllTicketGroups
andgetEventId
“thens”. So you should re-return your response inthen
to makeconsole.log
display your response.
UPDATE
-
Request chaining for tickets, quick example:
mounted() { this.getAllTicketGroups().then((response) => { let requests = []; this.allTickets.forEach((t) => { requests.push(this.getEventId(t.event_id)); }); return axios.all(requests); }); } ... getEventId: function(event_id){ if(!(event_id in this.findTickets) && this.eventsId.indexOf(event_id) == -1){ return axios.get('https://api.ticketpass.co/event/' + event_id,{ headers:{ "Content-Type" : "application/json", "Accept" : "application/json", "Authorization" : this.accessToken } }) .then(response => { console.log(response.data); this.findTickets[response.data.id] = response.data; }) console.log("Data Added"); }else{ console.log("IN Object"); } console.log(this.findTickets); }
👤Max Sinev
Source:stackexchange.com