//请求前拦截器
service.interceptors.request.use(
config => {
// 请求前需要设置header之类在此设置
if (service.showLoading) {
showFullScreenLoading()
}
config.headers['X-Requested-With'] = 'XMLHttpRequest'
config.headers['content-type'] = 'text/plain; charset=UTF-8'
return config
},
error => {
if (service.showLoading) {
tryHideFullScreenLoading()
}
return Promise.reject(error)
}
)
最后一行代码return Promise.reject(error),其作用是会将错误抛出,应该相当于如下这句话:
throw new Error("error");