From d7fb3356e8c033cbeab1d1bf9540dd70e2b4a068 Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 30 Jun 2020 15:26:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E6=AF=8F=E4=B8=AAajax=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/main.js | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 49ff78c..9c067b1 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "echarts": "^4.8.0", "element-ui": "^2.13.2", "lodash": "^4.17.15", + "nprogress": "^0.2.0", "vue": "^2.6.11", "vue-quill-editor": "^3.0.6", "vue-router": "^3.2.0", diff --git a/src/main.js b/src/main.js index a314445..cfc0251 100644 --- a/src/main.js +++ b/src/main.js @@ -14,17 +14,25 @@ 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/' -// 为每个请求头挂一个 token +// 为每个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))