I have method that calls ajax to my api and that response which returns I assigning it to an array. After that in template section with v-for
I display data. It render only one time after I change something in data to display. After refresh it is not displaying anymore.
No errors in console, and vue shows that array is filled with returned response.
Template:
<template>
<div class="row">
<div class="col-12">
<h5 class="component-title">Game board</h5>
<button v-for="number in board" v-bind:key="number.results" :class="'col-1 btn btn-'+number.colors">{{number.positionToId}}</button>
</div>
</div>
</template>
Script section:
import RouletteApi from "@/services/api/Roulette";
export default {
name: "GameBoard",
data() {
return {
board: []
};
},
created() {
this.getBoardLayout();
},
methods: {
getBoardLayout() {
RouletteApi.getLayout().then(response => {
//this.rLayout.orgResponse = response;
for (var i = 0; i < response.slots; i++) {
this.board[i] = {
results: response.results[i],
positionToId: response.positionToId[i],
colors: response.colors[i]
};
}
});
}
}
};
What am i doing wrong?
You have no reactivity by using that method to fill your array so try this using
push
function:or using
this.$set
instance method :