Hey guys I am trying to make a webpage that allows the user to see all the tickets that they can purchase or have purchased. But, the issue is that when the webpage has been loaded the event_id shows undefined within the console. I am not sure as to why this is.
I am using axios to get the event details from a server which is then pushed onto the webpage.
I have placed the code within the mounted function so that everything canbee seen as soon as the page is loaded.
Below is the JavaScript code that I am using.
data(){
return{
allTickets: [],
getTickets:{
seeTickets:{
event_id: this.event_id
}
},
findTickets: {},
}
},
mounted: function(){
console.log(this.accessToken)
axios.get('https://api.ticketpass.co/tickets',{
headers:{
"Content-Type" : "application/json",
"Accept" : "application/json"
}
})
.then(response =>{
console.log(response);
console.log(response.data);
console.log(response.status);
if(response.status === 200){
console.log(this.allTickets);
console.log(response.data.length);
console.log(response.data[i].event_id);
for(let i = 0; i < response.data.length; i++){
this.allTickets.push({
"some_id" : response.data[i].id,
"event_id" : response.data[i].event_id,
"created" : response.data[i].created,
"code" : response.data[i].code,
"user_id" : response.data[i].user_id
})
this.getTickets.seeTickets = {
"event_id" : response.data[i].event_id
}
console.log(!(response.data[i].event_id in this.findTickets));
if(!(response.data[i].event_id in this.findTickets)){
console.log("Not in Object", response.data[i].event_id, this.findTickets)
axios.get('https://api.ticketpass.co/event/' + response.data[i].event_id,{
headers:{
"Content-Type" : "application/json",
"Accept" : "application/json",
"Authorization" : this.accessToken
}
})
console.log("Data Added")
this.findTickets[response.data.id] = response.data;
}
else{
console.log("IN Object")
}
}
}
})
.catch(error =>{
console.log(error.response)
})
}
}
It would be much appreciated if someone could please help me out.
Many thanks.