关于vue router的问题,为什么会报这个错?

问题描述

我现在使用sessionStorage存的路由表,在页面刷新后,动态添加路由表就报错了

//
    created(){
        if(sessionStorage.getItem('user')){
                var localRoutes=sessionStorage.getItem('routes')
                console.log(localRoutes)
                console.log(this.$router)
               //使用这个方法添加动态路由报错
               this.$router.addRoutes(JSON.parse(localRoutes))
            }
        }

报错如下

Vue warn: Error in beforeCreate hook: "TypeError: Cannot read property 'call' of null",

这个是怎么回事尼?
该怎么解决

阅读 4.3k
3 个回答

看下是不是beforeCreate钩子里面使用了xx.call,而xx还没被创建

新手上路,请多包涵

这玩意应该是因为你component也一起存进sessionStorage里了叭

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题