From 3e31b71157da2c7f30e84a575f363f4e1894784a Mon Sep 17 00:00:00 2001 From: pjhmizn49 Date: Fri, 13 Dec 2024 09:13:14 +0800 Subject: [PATCH] ADD file via upload --- flower_user_front/src/main.js | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 flower_user_front/src/main.js diff --git a/flower_user_front/src/main.js b/flower_user_front/src/main.js new file mode 100644 index 0000000..8dbf080 --- /dev/null +++ b/flower_user_front/src/main.js @@ -0,0 +1,41 @@ +import Vue from 'vue' +import App from './App.vue' +import './plugins/axios' +import router from './router' +import store from './store' +import ElementUI from 'element-ui'; +import 'element-ui/lib/theme-chalk/index.css'; +import Cookie from "js-cookie"; + +Vue.config.productionTip = false +Vue.use(ElementUI); + +//添加全局前置导航守卫 +router.beforeEach((to,from,next) => { + //判断token是否存在 + const token = Cookie.get('token') + //token不存在且当前不在登录或注册页面,说明用户未登录,跳转至登录页面 + if (!token && to.name === 'register'){ + next() + } + else if(!token && to.name === 'login'){ + next() + } + //token不存在且当前为游客模式,放行 + else if (!token && to.name !== 'visitor'){ + next({name:'visitor'}) + } + else if(token && to.name === 'login'){ //token存在且当前页面为登录页面,用户已登录,跳转至首页 + next({name:'home'}) + } + else{ + next() + } +}) + +new Vue({ + router, + store, + el: '#app', + render: h => h(App) +}).$mount('#app') \ No newline at end of file