vue-router使用beforeEach钩子获取vuex里的state值,如何解决?

vue-router使用beforeEach钩子获取vuex里的state值,初始页面报错,如何解决?

router.beforeEach((to, from, next) => {

  console.log(router.app.$store.state.isLogin)

  if(!userinfo && to.path.indexOf('login') == -1){

     return next('/login')

  }else{

    return next()

  }

});

https://img1.mukewang.com/5b94f8fb0001439907320686.jpg

繁星点点滴滴
浏览 9469回答 2
2回答

陪伴而非守候

你在main.js中import store没有,引入之后直接如下面这样获取就可以了store.state.isLogin
打开App,查看更多内容
随时随地看视频慕课网APP