Is there a way to wait until my data of teamId is updated before opening the bootstrap-vue modal? At the moment on the first click to open the modal, the table in ModalResults is blank, on the second click, it's populated with the table data correctly, using teamId in the get api call. The data is always one click behind the actual click of the teamId clicked.
parent component:
<tr v-for="(item,i) in standings"
:key="i"
:class="defineColor(item)"
@click="getTeamId(item.team.id)"
v-b-modal="'modalId' + i">
<ModalContent :standings="standings" :teamId="teamId" />
...
data() {
return {
teamId: Number
};
},
methods: {
getTeamId(teamId) {
console.log("league Table: ", teamId);
this.teamId = teamId;
},
child component ModalContent:
<template>
<div>
<b-modal :id="'modalId' + i" v-for="(item,i) in standings" :key="'teamDetails'+ i">
<ModalResults :results="results" />
</b-modal>
...
export default {
name: "ModalContent",
props: {
standings: Array,
teamId: [Function, Number]
},
components: { ModalResults },
data() {
return {
results: []
};
},
methods: {
getResults(teamId) {
getData.getTeamResults
.get(teamId + "/matches?status=FINISHED")
.then(response => {
this.results = response.data.matches;
console.log("this.results: ", this.results);
})
.catch(error => console.log(error));
}
},
watch: {
teamId() {
let teamId = this.$props.teamId;
console.log("teamId watched: ", teamId);
teamId && this.getResults(teamId);
}
}
};