Vuex store.watch only accepts a function in Vue router guard

此生再无相见时 提交于 2021-02-17 06:05:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!