|
|
|
|
@ -0,0 +1,37 @@
|
|
|
|
|
import Vue from 'vue'
|
|
|
|
|
import './plugins/axios'
|
|
|
|
|
import App from './App.vue'
|
|
|
|
|
import router from './router'
|
|
|
|
|
import ElementUI from 'element-ui';
|
|
|
|
|
import 'element-ui/lib/theme-chalk/index.css';
|
|
|
|
|
import store from './store'
|
|
|
|
|
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 !== 'login'){
|
|
|
|
|
next({name:'login'})
|
|
|
|
|
}
|
|
|
|
|
else if(token && to.name === 'login'){ //token存在且当前页面为登录页面,用户已登录,跳转至首页
|
|
|
|
|
next({name:'statistic'})
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
next()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
new Vue({
|
|
|
|
|
router,
|
|
|
|
|
store,
|
|
|
|
|
el: '#app',
|
|
|
|
|
render: h => h(App),
|
|
|
|
|
created() {
|
|
|
|
|
store.commit('addMenu',router)
|
|
|
|
|
}
|
|
|
|
|
}).$mount('#app')
|