为每个ajax请求添加一个进度条

This commit is contained in:
xing 2020-06-30 15:26:12 +08:00
parent 8b739366c0
commit d7fb3356e8
2 changed files with 10 additions and 1 deletions

View File

@ -13,6 +13,7 @@
"echarts": "^4.8.0", "echarts": "^4.8.0",
"element-ui": "^2.13.2", "element-ui": "^2.13.2",
"lodash": "^4.17.15", "lodash": "^4.17.15",
"nprogress": "^0.2.0",
"vue": "^2.6.11", "vue": "^2.6.11",
"vue-quill-editor": "^3.0.6", "vue-quill-editor": "^3.0.6",
"vue-router": "^3.2.0", "vue-router": "^3.2.0",

View File

@ -14,17 +14,25 @@ import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme import 'quill/dist/quill.bubble.css' // for bubble theme
import timeline from 'element-ui/lib/timeline' import timeline from 'element-ui/lib/timeline'
import timelineItem from 'element-ui/lib/timeline-item' import timelineItem from 'element-ui/lib/timeline-item'
// 进度条
import NProgres from 'nprogress'
import 'nprogress/nprogress.css'
Vue.use(timeline) Vue.use(timeline)
Vue.use(timelineItem) Vue.use(timelineItem)
Vue.use(vueQuillEditor) Vue.use(vueQuillEditor)
Vue.component('table-tree', tableTree) Vue.component('table-tree', tableTree)
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/' axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
// 为每个请求头挂一个 token // 为每个ajax请求头挂一个 token 并加载进度条
axios.interceptors.request.use(config => { axios.interceptors.request.use(config => {
NProgres.start()
config.headers.Authorization = sessionStorage.getItem('token') config.headers.Authorization = sessionStorage.getItem('token')
return config return config
}) })
axios.interceptors.response.use(response => {
NProgres.done()
return response
})
Vue.filter('dataFormat', (time) => { Vue.filter('dataFormat', (time) => {
const dt = (new Date(time)) const dt = (new Date(time))