Set timeout error when using routes with VueJS

javascript, vue-router, vue.js

Solution

Don't pass `that` as the parameter of the anonymous function passed to `setTimeout`.

Doing so effectively resets `that` within the scope of the anonymous function because you are defining it again as a parameter for the function. That function is never given a parameter, so it is `undefined`, meaning that `that` is `undefined` when it tries to access the `$router` property.

Problem

I am using VueJS and I want to push data to the server and afterwards change the route. 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: Cannot read property '$router' of undefined Can anybody help?

Original source