在Vue中如何使用Cookie操作实例(2)

import Vue from 'vue' import Router from 'vue-router' import {post,fetch,patch,put} from '@/util/http' import {delCookie,getCookie} from '@/util/util' import Index from '@/views/index/Index' //首页 import Home from '@/views/index/Home' //主页 import right from '@/components/UserRight' //右侧 import userlist from '@/views/user/UserList' //用户列表 import usercert from '@/views/user/Certification' //用户审核 import userlook from '@/views/user/UserLook' //用户查看 import usercertlook from '@/views/user/UserCertLook' //用户审核查看 import sellbill from '@/views/ticket/SellBill' import buybill from '@/views/ticket/BuyBill' import changebill from '@/views/ticket/ChangeBill' import billlist from '@/views/bill/list' import billinfo from '@/views/bill/info' import addbill from '@/views/bill/add' import editsellbill from '@/views/ticket/EditSellBill' import ticketstatus from '@/views/ticket/TicketStatus' import addticket from '@/views/ticket/AddTicket' import userinfo from '@/views/user/UserInfo' //个人信息 import editpwd from '@/views/user/EditPwd' //修改密码 Vue.use(Router); const routes = [ { path: 'https://www.jb51.net/', name:'登录', component:Index }, { path: 'https://www.jb51.net/', name: 'home', component: Home, redirect: '/home', leaf: true, //只有一个节点 menuShow: true, iconCls: 'iconfont icon-home', //图标样式 children: [ {path:'/home', component: right, name: '首页', menuShow: true, meta:{requireAuth: true }} ] }, { path: 'https://www.jb51.net/', component: Home, name: '用户管理', menuShow: true, iconCls: 'iconfont icon-users', children: [ {path: '/userlist', component: userlist, name: '用户列表', menuShow: true, meta:{requireAuth: true }}, {path: '/usercert', component: usercert, name: '用户认证审核', menuShow: true, meta:{requireAuth: true }}, {path: '/userlook', component: userlook, name: '查看用户信息', menuShow: false,meta:{requireAuth: true}}, {path: '/usercertlook', component: usercertlook, name: '用户审核信息', menuShow: false,meta:{requireAuth: true}}, ] }, { path: 'https://www.jb51.net/', component: Home, name: '信息管理', menuShow: true, iconCls: 'iconfont icon-books', children: [ {path: '/sellbill', component: sellbill, name: '卖票信息', menuShow: true, meta:{requireAuth: true }}, {path: '/buybill', component: buybill, name: '买票信息', menuShow: true, meta:{requireAuth: true }}, {path: '/changebill', component: changebill, name: '换票信息', menuShow: true, meta:{requireAuth: true }}, {path: '/bill/editsellbill', component: editsellbill, name: '编辑卖票信息', menuShow: false, meta:{requireAuth: true}} ] }, { path: '/bill', component: Home, name: '票据管理', menuShow: true, iconCls: 'iconfont icon-books', children: [ {path: '/bill/list', component: billlist, name: '已开票据列表', menuShow: true, meta:{requireAuth: true }}, {path: '/bill/info', component: billinfo, name: '票据详细页', menuShow: false, meta:{requireAuth: true }}, {path: '/bill/add', component: addbill, name: '新建开票信息', menuShow: true, meta:{requireAuth: true }} ] }, { path: 'https://www.jb51.net/', component: Home, name: '系统设置', menuShow: true, iconCls: 'iconfont icon-setting1', children: [ {path: '/userinfo', component: userinfo, name: '个人信息', menuShow: true, meta:{requireAuth: true }}, {path: '/editpwd', component: editpwd, name: '修改密码', menuShow: true, meta:{requireAuth: true }} ] } ]; const router = new Router({ routes });

备注:请注意路由中的 meta:{requireAuth: true },这个配置,主要为下面的验证做服务。

if(to.meta.requireAuth),这段代码意思就是说,如果requireAuth: true ,那就判断用户是否存在。

如果存在,就继续执行下面的操作,如果不存在,就删除客户端的Cookie,同时页面跳转到登录页,代码如下。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyjzgp.html