-
Notifications
You must be signed in to change notification settings - Fork 145
/
Copy pathentry.js
91 lines (83 loc) · 2.19 KB
/
entry.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import Vue from 'vue'
import entry from './App'
import VueRouter from 'vue-router'
import Element from 'element-ui'
import hljs from 'highlight.js'
import routes from './route.config'
import demoBlock from './components/demo-block'
import SideNav from './components/side-nav'
import title from './i18n/title'
import 'element-ui/lib/theme-chalk/index.css';
import './assets/styles/color-brewer.css'
import './assets/styles/common.scss'
Vue.use(Element)
Vue.use(VueRouter)
Vue.component('demo-block', demoBlock)
Vue.component('side-nav', SideNav)
const globalEle = new Vue({
data: { $isEle: false } // 是否 ele 用户
})
Vue.mixin({
computed: {
$isEle: {
get: () => (globalEle.$data.$isEle),
set: (data) => { globalEle.$data.$isEle = data }
}
}
})
const router = new VueRouter({
mode: 'hash',
base: __dirname,
routes
})
router.beforeEach(async(to, from, next) => {
if (layui.tableFilter) {
layui.$('#commonTpl').html('')
layui.tableFilter.destroy([{
config:{id: 'myTable'}
},{
config:{id: 'myTable1'}
},{
config:{id: 'myTable2'}
},{
config:{id: 'myTable3'}
},{
config:{id: 'myTable5'}
},{
config:{id: 'myTable6'}
}])
}
// 单页面应用需要清除列配置记录,防止同名id造成的问题
if (layui.soulTable) {
layui.soulTable.clearOriginCols()
}
next()
})
router.afterEach(route => {
// https://github.com/highlightjs/highlight.js/issues/909#issuecomment-131686186
Vue.nextTick(() => {
const blocks = document.querySelectorAll('pre code:not(.hljs)')
Array.prototype.forEach.call(blocks, hljs.highlightBlock)
})
const data = title[route.meta.lang]
for (const val in data) {
if (new RegExp('^' + val, 'g').test(route.name)) {
document.title = data[val]
return
}
}
document.title = 'Element'
ga('send', 'event', 'PageView', route.name)
})
router.onError((error) => {
const pattern = /Loading chunk (\d)+ failed/g;
const isChunkLoadFailed = error.message.match(pattern);
const targetPath = router.history.pending.fullPath;
if (isChunkLoadFailed) {
router.replace(targetPath);
}
});
new Vue({ // eslint-disable-line
...entry,
router
}).$mount('#app')