From 98f7b7d47efd95b24b3fa0dbeda7bd2c0aa1420b Mon Sep 17 00:00:00 2001 From: smallwei <1634566606@qq.com> Date: Fri, 27 Apr 2018 11:34:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9ajax=E7=9A=84=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E7=AD=89=E5=BE=85UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/axios.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/router/axios.js b/src/router/axios.js index e35b570d..4bc7699d 100644 --- a/src/router/axios.js +++ b/src/router/axios.js @@ -8,21 +8,21 @@ import axios from 'axios' import store from '../store' import router from '../router/router'; import { getToken, setToken, removeToken } from '@/util/auth'; -import { Loading, Message } from 'element-ui' +import { Message } from 'element-ui' import errorCode from '@/const/errorCode' +import NProgress from 'nprogress' // progress bar +import 'nprogress/nprogress.css'// progress bar style //超时时间 axios.defaults.timeout = 30000; //跨域请求,允许保存cookie axios.defaults.withCredentials = true; +NProgress.configure({ showSpinner: false })// NProgress Configuration -let loadinginstace; let msg; //HTTPrequest拦截 axios.interceptors.request.use(config => { - loadinginstace = Loading.service({ - fullscreen: true - }); + NProgress.start() // start progress bar if (store.getters.access_token) { config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带token--['X-Token']为自定义key 请根据实际情况自行修改 } @@ -32,10 +32,10 @@ axios.interceptors.request.use(config => { }) //HTTPresponse拦截 axios.interceptors.response.use(data => { - loadinginstace.close(); + NProgress.done(); return data }, error => { - loadinginstace.close(); + NProgress.done(); let errMsg = error.toString(); let code = errMsg.substr(errMsg.indexOf('code') + 5); Message({