1.安装NProgress依赖包
npm install nprogress --save
2.在main.js 中导入NProgress包对应的js和css
import NProgress from ‘nprogress‘
import ‘nprogress/nprogress.cs‘
3.在request 拦截器中, 展示进度条 NProgress.start()
axios.interceptors.request.use(config => {
NProgress.start()
return config
})
4.在response 拦截器中, 隐藏进度条 NProgress.done()
axios.interceptors.response.use(config => {
NProgress.done()
return config
})