路由钩子函数
//main.js
router.beforeEach((to, from, next) => {
if (to.meta.Auth) {//需要登录
if (store.state.islogin) {
next();
} else {
router.push({ name: 'login' })
}
} else {//不需要登录
next();
}
})
//路由
{
path: '/admin',
name: 'admin',
meta: {
Auth: true, // 需要登录
},
component: Admin
}
//store
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);
const state = {
islogin:false
}