当后台限定必须用application/x-www-form-urlencoded数据格式提交表单时
import Qs
from "qs";
method
: "POST",
headers
: { "content-type": "application/x-www-form-urlencoded" },
data
: Qs
.stringify(data
),
以下为axios操作的补充 拦截器的post请求可以添加Content-Type头部,若后台已经写死,不传也可以
const instance
= axios
.create({
baseURL
: 'http://39.108.147.139:9091',
timeout
: 3000
})
instance
.interceptors
.request
.use(function (config
) {
if(config
.method
== 'post'){
config
.headers
['Content-Type'] = 'application/x-www-form-urlencoded'
}
return config
;
}, function (error
) {
return Promise
.reject(error
);
});