Files
chaoyangpc/src/main.js
2019-09-23 20:12:30 +08:00

56 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import http from '../static/js/http'
import ElementUI from 'element-ui'
import md5 from 'js-md5'
import '../static/css/reset.css'
import '../static/css/swiper.css'
import '../static/fonts/iconfont.css'
import 'element-ui/lib/theme-chalk/index.css'
router.beforeEach((to, from, next) => {
if (to.meta.requireAuth) {
// 判断该路由是否需要登录权限
if (localStorage.token) {
// 获取当前的token是否存在
console.log('token存在')
next()
} else {
console.log('token不存在')
next({
path: '/login', // 将跳转的路由path作为参数登录成功后跳转到该路由
query: { redirect: to.fullPath }
})
}
} else {
// 如果不需要权限校验,直接进入路由界面
next()
}
})
Vue.prototype.$md5 = md5
Vue.prototype.$http = http
Vue.prototype.$jump = function (url) {
this.$router.push({
name: url
})
}
Vue.prototype.$jParams = function (url, parameters) {
this.$router.push({
name: url,
params: parameters
})
}
Vue.use(ElementUI)
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')