My Vue.js and Axios setup involves making an API call, where I aim to temporarily change the value of a variable from false to true using SetTimeout. However, there seems to be an issue with Vue not responding unless the variable name is hard coded.
Within my template
<i v-if="fnameEntered" id="fnameCheckPlacement" class="fnameCheck form-control-feedback glyphicon glyphicon-ok" style="margin-right: 10%;"></i>
And in my script
methods: {
submitFirstName: function(event){
this.updateUserInfo(this.fname, "fname", this.fnameEntered);
},
updateUserInfo: function (val, field, checkMark) {
axios.post('/userprofilepage', {
val: val,
field: field
})
.then(response => {
let self = this;
setTimeout(function() {
self.checkMark = false;
}, 2000);
this.checkMark = true;
})
.catch(error => {
console.log(error);
})
.finally(() => this.loading = false)
},
}
I am attempting to pass this.fnameEntered
as the checkMark
variable into updateUserInfo. When I explicitly set this.fnameEntered = true
and this.fnameEntered = false
, it works as expected.
However, when trying to use "this.checkMark" or "self.checkMark," nothing happens. What am I missing?