From 2f5b951911dca56b6fe48e69d026a2adc401e79e Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 30 Jun 2020 16:53:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E5=88=AB=E4=B8=BA=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E5=92=8C=E7=BA=BF=E4=B8=8A=E7=8E=AF=E5=A2=83=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E4=B8=8D=E5=90=8C=E7=9A=84main.js=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main-dev.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ src/main-prod.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ vue.config.js | 8 +++++++ 3 files changed, 120 insertions(+) create mode 100644 src/main-dev.js create mode 100644 src/main-prod.js diff --git a/src/main-dev.js b/src/main-dev.js new file mode 100644 index 0000000..cfc0251 --- /dev/null +++ b/src/main-dev.js @@ -0,0 +1,56 @@ +import Vue from 'vue' +import App from './App.vue' +import router from './router/router' +import ElementUI from 'element-ui' +import 'element-ui/lib/theme-chalk/index.css' +import './assets/fonts/iconfont.css' +import './assets/css/globel.css' +import tableTree from 'vue-table-with-tree-grid' +import axios from 'axios' +import vueQuillEditor from 'vue-quill-editor' + +import 'quill/dist/quill.core.css' // import styles +import 'quill/dist/quill.snow.css' // for snow theme +import 'quill/dist/quill.bubble.css' // for bubble theme +import timeline from 'element-ui/lib/timeline' +import timelineItem from 'element-ui/lib/timeline-item' +// 进度条 +import NProgres from 'nprogress' +import 'nprogress/nprogress.css' + +Vue.use(timeline) +Vue.use(timelineItem) +Vue.use(vueQuillEditor) +Vue.component('table-tree', tableTree) +axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/' +// 为每个ajax请求头挂一个 token 并加载进度条 +axios.interceptors.request.use(config => { + NProgres.start() + config.headers.Authorization = sessionStorage.getItem('token') + return config +}) +axios.interceptors.response.use(response => { + NProgres.done() + return response +}) + +Vue.filter('dataFormat', (time) => { + const dt = (new Date(time)) + const y = dt.getFullYear() + const m = (dt.getMonth() + 1 + '').padStart(2, '0') + const d = (dt.getDate() + '').padStart(2, '0') + const H = dt.getHours().toString().padStart(2, '0') + const i = dt.getMinutes().toString().padStart(2, '0') + const s = dt.getSeconds().toString().padStart(2, '0') + return `${y}-${m}-${d} ${H}:${i}:${s}` +}) + +Vue.prototype.$http = axios +Vue.use(ElementUI) + +Vue.config.productionTip = false + +new Vue({ + router, + render: h => h(App) +}).$mount('#app') diff --git a/src/main-prod.js b/src/main-prod.js new file mode 100644 index 0000000..cfc0251 --- /dev/null +++ b/src/main-prod.js @@ -0,0 +1,56 @@ +import Vue from 'vue' +import App from './App.vue' +import router from './router/router' +import ElementUI from 'element-ui' +import 'element-ui/lib/theme-chalk/index.css' +import './assets/fonts/iconfont.css' +import './assets/css/globel.css' +import tableTree from 'vue-table-with-tree-grid' +import axios from 'axios' +import vueQuillEditor from 'vue-quill-editor' + +import 'quill/dist/quill.core.css' // import styles +import 'quill/dist/quill.snow.css' // for snow theme +import 'quill/dist/quill.bubble.css' // for bubble theme +import timeline from 'element-ui/lib/timeline' +import timelineItem from 'element-ui/lib/timeline-item' +// 进度条 +import NProgres from 'nprogress' +import 'nprogress/nprogress.css' + +Vue.use(timeline) +Vue.use(timelineItem) +Vue.use(vueQuillEditor) +Vue.component('table-tree', tableTree) +axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/' +// 为每个ajax请求头挂一个 token 并加载进度条 +axios.interceptors.request.use(config => { + NProgres.start() + config.headers.Authorization = sessionStorage.getItem('token') + return config +}) +axios.interceptors.response.use(response => { + NProgres.done() + return response +}) + +Vue.filter('dataFormat', (time) => { + const dt = (new Date(time)) + const y = dt.getFullYear() + const m = (dt.getMonth() + 1 + '').padStart(2, '0') + const d = (dt.getDate() + '').padStart(2, '0') + const H = dt.getHours().toString().padStart(2, '0') + const i = dt.getMinutes().toString().padStart(2, '0') + const s = dt.getSeconds().toString().padStart(2, '0') + return `${y}-${m}-${d} ${H}:${i}:${s}` +}) + +Vue.prototype.$http = axios +Vue.use(ElementUI) + +Vue.config.productionTip = false + +new Vue({ + router, + render: h => h(App) +}).$mount('#app') diff --git a/vue.config.js b/vue.config.js index a5bf827..b639875 100644 --- a/vue.config.js +++ b/vue.config.js @@ -2,5 +2,13 @@ module.exports = { devServer: { port: 8887, open: true + }, + chainWebpack: config => { + config.when(process.env.NODE_ENV === 'production', config => { + config.entry('app').clear().add('./src/main-prod.js') + }) + config.when(process.env.NODE_ENV === 'development', config => { + config.entry('add').clear().add('./src/main-dev.js') + }) } }