main.js 1.7 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 5 6 7 8
// import Vue from 'vue'
// import axios from 'axios'
// import hljs from 'highlight.js'
// import importElementComponents from './importElement'
// import importEchartsComponents from './importEchartsComponents'
yma16's avatar
yma16 已提交
9 10 11
// 样式cnd
import 'github-markdown-css/github-markdown.css'
import 'nprogress/nprogress.css'
12
// 无需cdn
yma16's avatar
yma16 已提交
13
import useRouter from './router'
yma16's avatar
yma16 已提交
14
import VueRouter from 'vue-router'
15
import cookies from 'vue-cookies'
yma16's avatar
yma16 已提交
16
import App from './App'
yma16's avatar
yma16 已提交
17 18
import 'highlight.js/styles/github.css'

yma16's avatar
yma16 已提交
19
const env = process.env.NODE_ENV && false
yma16's avatar
yma16 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

// 公共的部分

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')
// 路由
const router = useRouter(Vue, VueRouter)
yma16's avatar
yma16 已提交
41 42 43
// 生产环境
if (env === 'production') {
    try {
yma16's avatar
yma16 已提交
44
        // 全局引入
yma16's avatar
yma16 已提交
45
        Vue.config.productionTip = false
yma16's avatar
yma16 已提交
46

yma16's avatar
yma16 已提交
47 48 49 50 51 52 53 54 55 56
        new Vue({
            el: '#app',
            router,
            components: { App },
            template: '<App/>'
        })
    } catch (e) {
        throw Error(e)
    }
} else {
yma16's avatar
yma16 已提交
57 58 59 60 61
    // // 按需引入elementui
    // importElementComponents(Vue)
    //
    // // 按需引入echarts
    // importEchartsComponents(Vue)
yma16's avatar
yma16 已提交
62 63 64 65 66 67 68
    Vue.config.productionTip = false

    new Vue({
        el: '#app',
        router,
        components: { App },
        template: '<App/>'
yma16's avatar
yma16 已提交
69
    })
yma16's avatar
yma16 已提交
70
}