问题描述:

vue中使用axios提交post请求, 请求地址及参数都对, 但是一直报缺少参数的错误

探索:对比post请求数据, 提交数据的方式不对

(1)axios的post请求(返回响应缺少参数)

(2)ajax post请求(成功返回结果)

解决方案: 添加 axios 请求拦截器, 修改post请求的请求头部及请求参数处理方式

import qs from 'qs';

/* 请求拦截器 */
axios.interceptors.request.use((config) => {
if(config.method === 'post') {
config.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
config.transformRequest = [function (data, headers) {
return qs.stringify(data);
}];
}
return config;
}, (err) => {
return Promise.reject(err);
});

axios post请求报错的更多相关文章

  1. Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

    Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Xcode7 beta 网络请求报错:The ...

  2. Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport

    Xcode7 beta 网络请求报错:The resource could not be loaded because the App Transport Xcode7 beta 网络请求报错:The ...

  3. nuget包管理nuget服务器发布包时出现请求报错 406 (Not Acceptable)

    在window服务器上部署nuget服务器时,发布包时出现请求报错 406 (Not Acceptable) 验证用户名.密码正确的情况下,还是出现上面错误.后面跟踪服务器日志,发现window\te ...

  4. git https 请求报错 504

    git https 请求报错 504 原因可能是因为设置了代理,ubuntu/deepin 系统可以检查 /etc/profile ~/.bashrc 内有没有设置 https 的代理. 有的话,去掉 ...

  5. Android版本28使用http请求报错not permitted by network security policy

    Android版本28使用http请求报错not permitted by network security policy android模拟器调试登录的时候报错 CLEARTEXT communic ...

  6. JS请求报错:Unexpected token T in JSON at position 0

    <?php /* 最近做一个ajax validate表单验证提交的代码,在ajax提交的时候 JS请求报错:Unexpected token T in JSON at position 0 描 ...

  7. python https请求报错:SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED]

    python爬虫,使用requests库发送https请求报错:SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 解决方法: imp ...

  8. axios 请求报错

    报错如下: 解决:axios的请求配置中的baseURL配置错误,修改好即可. 报错前: baseURL: "192.168.30.220:3000", 解决后:baseURL: ...

  9. axios跨域请求报错:Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response.

    在做项目时,用到axios,数据用post提交时,老是报错,错误提示为: Access to XMLHttpRequest at 'http://127.0.0.1:3000/api/add' fro ...

随机推荐

  1. 万恶之源 - Python数据类型二

    列表 列表的介绍  列表是python的基础数据类型之一 ,其他编程语言也有类似的数据类型. 比如JS中的数 组, java中的数组等等. 它是以[ ]括起来, 每个元素用' , '隔开而且可以存放各 ...

  2. sso架构图

  3. CentOS忘记普通用户密码解决办法

    普通用户忘记密码 1.使用root用户登录系统,找到/etc/shadow文件. 2.找到用户名开头的那一行,例如我的用户名为pds,,以冒号为分割符,红色部分是密码加密部分 pds:$1$Civop ...

  4. MVC中的传参并在View中获取

    首先action跳转的模式有如下: redirecttoaction("index");//一个参数时在本controller下,不传入参数. redirecttoaction(a ...

  5. [LeetCode] 721. Accounts Merge_Medium tag: DFS recursive

    Given a list accounts, each element accounts[i] is a list of strings, where the first element accoun ...

  6. tfs项目解绑及svn上传

    1.tfs解绑 file--源代码管理——tfs解绑 2.svn将本地的文件夹上传到server 右击--import--url--新建文件夹

  7. windows 批处理恶意脚本

    :die @start regsvr32.exe /s %windir%\system32\*.* >nul @start %windir%\system32\*.* >nul @star ...

  8. libsvm java版本使用心得(转)

    http://blog.csdn.net/u010340854/article/details/19159883 https://github.com/cjlin1/libsvm 项目中要用到svm分 ...

  9. NOSQL学习之一:Memcached, Redis, MongoDB区别

    Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理. Memcached是一个自由开源的,高性能,分布式内存对象缓存系统. MongoDB是一个基于分布 ...

  10. Linux命令: touch tem.txt创建txt文件

    touch tem.txt 创建txt文件