Vue-router: this.$router in setTimeout doesn't work

Created on 7 Dec 2017  路  3Comments  路  Source: vuejs/vue-router

Version

3.0.1

Reproduction link

https://jsfiddle.net/mu6f7zj6/

Steps to reproduce

click Go to Foo , and console said Cannot read property 'push' of undefined.

What is expected?

1s after clicked Go to Foo should redirect to '/' (home), and 'foo' should disapear

What is actually happening?

Cannot read property 'push' of undefined.

All 3 comments

There's nothing related to Vue, that's because you're using wrong this context is setTimeout callback.

You should learn more about pure js before using Vue.

solved by add "var self = this, self.$router.push()"

"tonywangcn" Good Job

Was this page helpful?
0 / 5 - 0 ratings

Related issues

posva picture posva  路  3Comments

posva picture posva  路  3Comments

gil0mendes picture gil0mendes  路  3Comments

kerlor picture kerlor  路  3Comments

thomas-alrek picture thomas-alrek  路  3Comments