main.js 2.3 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
//vue cdn
yma16's avatar
yma16 已提交
4
import Vue from 'vue'
yma16's avatar
yma16 已提交
5
import VueRouter from 'vue-router'
yma16's avatar
yma16 已提交
6
import axios from 'axios'
yma16's avatar
yma16 已提交
7
import hljs from 'highlight.js'
yma16's avatar
yma16 已提交
8 9
import importElementComponents from './importElement'
import importEchartsComponents from './importEchartsComponents'
yma16's avatar
yma16 已提交
10
// 样式cnd
yma16's avatar
yma16 已提交
11 12
import 'github-markdown-css/github-markdown.css'
import 'nprogress/nprogress.css'
yma16's avatar
yma16 已提交
13 14 15 16 17 18 19 20 21 22 23 24 25 26
// 无需cdn
import useRouter from './router'
import cookies from 'vue-cookies'
import App from './App'
import 'highlight.js/styles/github.css'
import * as echarts from 'echarts/core'


const env = process.env.NODE_ENV
// 生产环境
if (env === 'production') {
    try {
    // 路由
        const router = useRouter(Vue, VueRouter)
yma16's avatar
yma16 已提交
27

yma16's avatar
yma16 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
        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.$echarts = echarts
44

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

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

yma16's avatar
yma16 已提交
60 61
    // 按需引入elementui
    importElementComponents(Vue)
yma16's avatar
yma16 已提交
62

yma16's avatar
yma16 已提交
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
    // 按需引入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 已提交
88
    })
yma16's avatar
yma16 已提交
89
}