Reputation: 169
I want to do this.$router.push(path)
inside module file of vuex.
As this is not defined there, how could I perform this.
Upvotes: 3
Views: 1447
Reputation: 2268
Just import the router and you'll be able to use it, like this:
import router from 'path/to/router'
router.push(path)
Why does it work like this:
In a Vue file, this
is binded to the Vue object which is why you can use certain methods that are available there like $router or $store.
However in a normal JS file this
is just binded to the global object that does not contain any of Vue's special functionality, which is why you have to import the router manually.
Upvotes: 3