我是写在request.js中做的拦截处理
import axios from 'axios'
const baseURL = process.env.VUE_APP_BASE_URL
const http = axios.create({ baseURL: baseURL })
// 请求拦截器
http.interceptors.request.use(
config => {
// config.headers.umcRequestUserName = 9117436
config.headers['umc-request-user-name'] = 9117436
return config
},
error => {
return Promise.reject(error)
}
)
// 响应拦截器
http.interceptors.response.use(
response => {
// 异常返回
if (response.data.code !== '200') {
ElMessage({
message: response.data.message,
type: 'error',
duration: 4000
})
}
return response.data
},
error => {
ElMessage({
message: error.message,
type: 'error',
duration: 4000
})
return Promise.reject(error)
}
)
export default http
在页面中发送axios请求时,报Uncaught (in promise) TypeError: Cannot read property ‘cancelToken’ of undefined