main.js 2.5 KB
Newer Older
yma16's avatar
yma16 已提交
1 2
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
yma16's avatar
yma16 已提交
3 4 5 6
// import Vue from 'vue'
// import VueRouter from 'vue-router'
// import axios from 'axios'
// import hljs from 'highlight.js'
yma16's avatar
yma16 已提交
7
import useRouter from './router'
8
import cookies from 'vue-cookies'
yma16's avatar
yma16 已提交
9
import App from './App'
10 11
// import importElementComponents from './importElement'
// import importEchartsComponents from './importEchartsComponents'
yma16's avatar
yma16 已提交
12
// 样式
yma16's avatar
yma16 已提交
13
// import 'github-markdown-css/github-markdown.css'
14
// import 'nprogress/nprogress.css'
yma16's avatar
yma16 已提交
15
import 'highlight.js/styles/github.css'
16
import * as echarts from 'echarts/core'
17

yma16's avatar
yma16 已提交
18

yma16's avatar
yma16 已提交
19 20 21 22 23 24 25
const env = process.env.NODE_ENV
// 生产环境
if (env === 'production') {
    try {
    // 路由
        const router = useRouter(Vue, VueRouter)

26 27 28 29 30
        // // 按需引入elementui
        // importElementComponents(Vue)
        //
        // // 按需引入echarts
        // importEchartsComponents(Vue)
yma16's avatar
yma16 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

        Vue.config.productionTip = false
        Vue.use(cookies)
        Vue.use(hljs)
        Vue.directive('highlight', function (el) {
            const blocks = el.querySelectorAll('pre code')
            blocks.forEach((block) => {
                hljs.highlightBlock(block)
            })
        })
        // cookie
        Vue.prototype.$cookies = cookies
        // axios
        Vue.use(axios)
        Vue.prototype.$axios = axios
        window.$axios_w = axios
47
        Vue.prototype.$echarts = echarts
48

yma16's avatar
yma16 已提交
49
        Vue.prototype.$cookies.set('user_session', 'null')
yma16's avatar
yma16 已提交
50

yma16's avatar
yma16 已提交
51 52 53 54 55 56 57 58 59 60 61 62
        new Vue({
            el: '#app',
            router,
            components: { App },
            template: '<App/>'
        })
    } catch (e) {
        throw Error(e)
    }
} else {
    // 路由
    const router = useRouter(Vue, VueRouter)
yma16's avatar
yma16 已提交
63

yma16's avatar
yma16 已提交
64 65
    // 按需引入elementui
    importElementComponents(Vue)
yma16's avatar
yma16 已提交
66

yma16's avatar
yma16 已提交
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
    // 按需引入echarts
    importEchartsComponents(Vue)

    Vue.config.productionTip = false
    Vue.use(cookies)

    Vue.use(hljs)
    Vue.directive('highlight', function (el) {
        const blocks = el.querySelectorAll('pre code')
        blocks.forEach((block) => {
            hljs.highlightBlock(block)
        })
    })
    // cookie
    Vue.prototype.$cookies = cookies
    // axios
    Vue.use(axios)
    Vue.prototype.$axios = axios
    window.$axios_w = axios
    Vue.prototype.$cookies.set('user_session', 'null')
    new Vue({
        el: '#app',
        router,
        components: { App },
        template: '<App/>'
yma16's avatar
yma16 已提交
92
    })
yma16's avatar
yma16 已提交
93
}