axios非简单会有options请求。用以下代码解决了,请问下patch和delete请求要怎么去options?和post一样的处理并不行。请高手指点一二
axios.defaults.baseURL = location.protocol + '//' + document.domain + ':5000'
axios.interceptors.request.use(function(config) {
config.headers['Content-Type'] = 'application/x-www-form-urlencoded'
if (config.method === 'post') {
config.data = qs.stringify(config.data)
}
return config
}, (error) => {
alert("错误的传参");
return Promise.reject(error);
})
仔细看下 MDN 上的介绍
patch 和 delete 方法,浏览器会发出预检请求,即options请求
除非你改成post请求