美文网首页
vue 验证token之路由验证以及设置网站title

vue 验证token之路由验证以及设置网站title

作者: 安徒生1997 | 来源:发表于2021-03-19 09:28 被阅读0次

1.router目录下的index.js

2.main.js

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

  if(to.meta.root) {

    if(token) {

      next();

    }else{

      console.log('请先登录')

    }

  }else{

    next();

  }

})

3.main.js设置网站title

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

  //路由发生改变时,触发

  window.document.title = to.meta.title == undefined ? 'xxx' : 'xxx-'+to.meta.title;

  next();

})

相关文章

网友评论

      本文标题:vue 验证token之路由验证以及设置网站title

      本文链接:https://www.haomeiwen.com/subject/mhxvcltx.html