您当前的位置: 首页 > 

苗先生的PHP记录

暂无认证

  • 5浏览

    0关注

    190博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Vue2 token判定路由操作

苗先生的PHP记录 发布时间:2021-11-20 13:53:05 ,浏览量:5

本人是使用的cookie登录 , 需要没有登录就跳转登录页

安装cookie

npm install vue-cookies --save

在main.js 全局引用

import VueCookies from 'vue-cookies'

Vue.use(VueCookies)

使用cookie , 过期时间为s

this.$cookies.get(keyName)  


this.$cookies.set(keyName, value[, expireTimes[, path[, domain[, secure]]]]) 

this.$cookies.remove(keyName [, path [, domain]])  

下面是router的index.js

router.beforeEach((to ,from ,next) => {
    if (to.path === '/login'){
        next()
    }
    const token = Vue.$cookies.get('token');
    console.log(token);
    if (!token || token === '' || token == null){
        next('/login')
    }
    next()
})

关注
打赏
1665468453
查看更多评论
立即登录/注册

微信扫码登录

0.0452s