当后台限定必须用application/x-www-form-urlencoded数据格式提交表单时

import Qs from "qs";

//需要转换的数据data
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);
  });

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐