提交 11008c1c 编写于 作者: X xjh22222228

feat: Add NProgress

上级 ffaa2604
// Copyright @ 2018-2021 xiejiahe. All rights reserved. MIT license.
import axios from 'axios'
import NProgress from 'nprogress'
import { getToken } from '../utils/user'
const httpInstance = axios.create({
......@@ -12,6 +13,8 @@ const token = getToken()
Object.setPrototypeOf(httpInstance, axios)
httpInstance.interceptors.request.use(function (config) {
NProgress.start()
config.headers = {
Authorization: `token ${token}`,
...config.headers
......@@ -19,14 +22,16 @@ httpInstance.interceptors.request.use(function (config) {
return config
}, function (error) {
NProgress.done()
return Promise.reject(error)
})
httpInstance.interceptors.response.use(function (res) {
NProgress.done()
return res
}, function (error) {
NProgress.done()
return Promise.reject(error)
})
......
......@@ -1326,6 +1326,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.35.tgz#42c953a4e2b18ab931f72477e7012172f4ffa313"
integrity sha512-Lt+wj8NVPx0zUmUwumiVXapmaLUcAk3yPuHCFVXras9k5VT9TdhJqKqGVUQCD60OTMCl0qxJ57OiTL0Mic3Iag==
"@types/nprogress@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@types/nprogress/-/nprogress-0.2.0.tgz#86c593682d4199212a0509cc3c4d562bbbd6e45f"
integrity sha512-1cYJrqq9GezNFPsWTZpFut/d4CjpZqA0vhqDUPFWYKF1oIyBz5qnoYMzR+0C/T96t3ebLAC1SSnwrVOm5/j74A==
"@types/parse-json@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
......@@ -6077,6 +6082,11 @@ npmlog@^4.1.2:
gauge "~2.7.3"
set-blocking "~2.0.0"
nprogress@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1"
integrity sha1-y480xTIT2JVyP8urkH6UIq28r7E=
nth-check@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-1.0.2.tgz#b2bd295c37e3dd58a3bf0700376663ba4d9cf05c"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册