Set timeout error when using routes with VueJS
I am using VueJS and I want to dump data to the server and change the route afterwards.
I've tried this:
saveSupportArea: function () {
this.toast("success");
var that = this;
setTimeout(function(that){
that.$router.push('/areas/');
}, 3000);
});
But I am getting this error:
Uncaught TypeError: Unable to read property '$ router' of undefined
Does anyone help?
source to share
Don't pass that
an anonymous function passed to a parameter as a parameter setTimeout
.
Execution so efficiently dumps that
within the scope of the anonymous function, because you again define it as a parameter to the function. This function never gets parameter, so it is undefined
, that means that that
there is undefined
, as he tries to gain access to the property $router
.
source to share