对角另一面
对角另一面

Reputation: 383

How can i use vuex's actions in vue-router's beforeEach

I want to check if the data is in store before every router change, if the data is not in the vuex, i want to use vuex's actions to get the data from server. so how can i user actions in beforeEach.

i use the vue2.0

Upvotes: 1

Views: 1550

Answers (2)

Marek Urbanowicz
Marek Urbanowicz

Reputation: 13674

All you have to do is import store from '/vuex and actions Depends how you built your actions you can be pushed to pass store instance to action. Other than that - it is straight forward.

Upvotes: 2

对角另一面
对角另一面

Reputation: 383

can use router.app.$store.dispatch('actionName')

Upvotes: 4

Related Questions