I need to update my variable this.xCtesPorRuta immediately after an axios call so I can show some info from the database on an element like a select. The axios call is activated with a button's v-on:click event.
I am storing the axios response on the variable, but it doesn't change immediately, it does so only when another element is clicked. I'm trying to force the update with nexttick but with no success.
First attempt:
var request = {rutas:this.xRutasSeleccionadas , tipos:this.xTipos}
axios.post('/querys/', request).then(response => this.xCtesPorRuta = response.data)
this.$nextTick(function() {
this.$forceUpdate();
});
I know Vue has issues updating arrays instantly, but I've manage before to force an array change by using the splice method, followed by the nextTick/forceUpdate hack. Never after an axios call though.
EDIT: I was using this
incorrectly here. Thanks to @Demonyowh and @fracz for the help on that part.
Second attempt. The result is the same as the first attemp:
var myVar = this;
var request = {rutas:this.xRutasSeleccionadas , tipos:this.xTipos}
axios.post('/querys/', request).then(function (response) {
myVar.xCtesPorRuta = [];
for (var i=0; i<response.data.length; i++) {
myVar.xCtesPorRuta.splice(i, 1, response.data[i]);
}
})
this.$nextTick(function() {
this.$forceUpdate();
});
Turns out using splice
didn't help this time.