全局设置axios 默认值
axios.defaults.headers.post['Content-Type']
单独给接口设置headers
axios({
method: "get",
url: "/api/Department/GetOrgCode",
headers: {'this-is-id': true},
}).then(res=>{
console.log(res)
}).catch(err=>{
console.log(err)
})
给满足条件的接口设置heaers (在axios拦截器中添加headers 属性)
axios.interceptors.request.use(function (config) {
if(!config.url.includes('vod2.qcloud.com')){
config.headers.post['ignore_verify_bind_org'] = true;
config.headers.get['ignore_verify_bind_org'] = true;
}
config.withCredentials = true;
return config;
}, function (error) {
return Promise.reject(error);
});
axios.interceptors.response.use(function (response) {
if (response.status == 401 || response.status == 302) {
location.href = "#/login";
return response.data;
}
return response;
}, function (error) {
let msg = error.response.data.Error || '请求失败,请重试!'
ElementUI.Message({
showClose: true,
message: msg,
type: "error",
duration: 2000
});
return Promise.reject(error);
});