发表于: 2019-10-11 22:53:24
1 809
今天完成的事情:
1.把日期修改了一下,使得开始和结束是同一天的时候,实际是这天的0点到23:59:59,然后添加了路由守卫,使得不从登录页面进去的时候,会没有权限,直接跳转到登录页面:
vuex.js:
export default new Vuex.Store({
//state里面只放置全局需要共用的属性
state: {
vueId:'',
vueData:{},
isLogin:0 //初始时候给一个 isLogin=0 表示用户未登录
},
//更改 Vuex 的 store 中的状态的唯一方法是提交 mutation,此时里面的必须是同步函数
mutations: {
changeId(state,payload){
state.vueId=payload;
},
changeLogin(state,data){
state.isLogin = data;
}
},
router.js:
import Vue from 'vue';
import Router from 'vue-router';
import Load from './views/Load.vue';
import store from './store'
Vue.use(Router);
const router = new Router({
mode: 'history',
routes: [
{
path: '/',
component: Load,
},
{
path: '/hom',
component: () => import('./views/Hom.vue'),
name: 'hom',
meta: {
auth: true// 设置当前路由需要校验
},
children: [
{
path: '',
component: () => import('./components/Back.vue'),
},
{
path: 'pass',
component: () => import('./components/Pass.vue'),
},
{
path: 'increase',
component: () => import('./components/Increase.vue'),
},
{
path: 'edit',
component: () => import('./components/Edit.vue'),
},
{
path: 'role',
component: () => import('./components/Role.vue'),
},
]
},
],
});
router.beforeEach((to, from, next) => {
if (to.matched.some(m => m.meta.auth)) {
// 对路由进行验证
if(store.state.isLogin==100) { // 已经登陆
next() // 正常跳转到设置好的页面
}
else {
// 未登录则跳转到登陆界面,query:{ Rurl: to.fullPath}表示把当前路由信息传递过去方便登录后跳转回来;
next({ path: '/', query: { Rurl: to.fullPath } })
}
} else {
next()
}
})
export default router;
load.vue:
this.$store.commit('changeLogin','100') //登录后改变登录状态 isLogin = 100
hom.vue:
this.$store.commit("changeLogin", "0");
明天计划:
继续写复盘ppt,把自己学到的能总结出来然后能说出来。
评论