forked from wanghaichao0611/Vue-SpringCloud-Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
79 lines (63 loc) · 1.92 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import jquery1 from 'jquery'
import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap/dist/js/bootstrap.min'
import 'bootstrap/dist/js/bootstrap'
import 'bootstrap/dist/js/npm'
import axios from "./api/axios"
import qs from 'qs'
import ViewUI from 'view-design'
import elementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'view-design/dist/styles/iview.css'
import Alert from './api/Alert'
import mavonEditor from 'mavon-editor'
import hljs from "highlight.js"
import 'highlight.js/styles/default.css'
import VCharts from 'v-charts'
import nocaptcha from 'vue-nocaptcha'
Vue.use(nocaptcha);
Vue.use(VCharts);
Vue.use(Alert);
Vue.prototype.$qs = qs;
Vue.use(jquery1);
Vue.config.productionTip = false;
Vue.prototype.$http=axios;
Vue.use(ViewUI);
Vue.use(elementUI);
Vue.use(mavonEditor);
// 定义自定义指令 highlight 代码高亮
Vue.directive('highlight',function (el) {
let blocks = el.querySelectorAll('pre code');
blocks.forEach((block)=>{
hljs.highlightBlock(block)
})
})
//钩子方法验证Token是否存在
router.beforeEach((to, from, next) => {
//改变网页的标题
window.document.title = to.meta.title;
//强制登录并且检测token
let token = localStorage.getItem('token');
if (!token && to.path !== '/login' && to.path !== '/register' && to.path !== '/') {
return next('/login')
}
ViewUI.LoadingBar.start();
next();
});
//返回页面的顶端
router.afterEach(route => {
window.scrollTo(0,0);
ViewUI.LoadingBar.finish();
});
/* eslint-disable no-new */
new Vue({
el: '#app',//document.getElementById('app')=#app,el用于指定一个页面已存在的DOM元素来挂载Vue实例
router,
template: '<App/>',
components: { App }
})