问题
I am trying to watch and wait until Vue router guard will get final value from Vuex however it throws [vuex] store.watch only accepts a function
Here is the code:
const isAdmin = _.get(store, 'getters.user/isAdmin', undefined)
if (to.matched.some(record => record.meta.isAdmin)) {
if (isAdmin === undefined) {
const watcher = store.watch(isAdmin, isAdmin => {
watcher() // stop watching
if (!isAdmin) next({ path: '/not-available' })
})
} else if (serv.isAuth() && !isAdmin) {
next({ path: '/not-available' })
}
}
What is wrong and how can I fix it?
来源:https://stackoverflow.com/questions/64511941/vuex-store-watch-only-accepts-a-function-in-vue-router-guard