美文网首页
Axios里POST application/x-www-for

Axios里POST application/x-www-for

作者: AAA前端 | 来源:发表于2019-05-17 10:49 被阅读0次

    axios发起post请求,后台需要form表单形式,按照文档发送post请求,但是发送数据变成字符串形式,后面还多了个分号。

    this.$axios
          .post(Api.initCheapOrder, {name: 'zs'}, {'headers': {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}})  
            .then(res => {
                  .......
            }).catch(e=>{......})
    
    image.png

    解决办法,引入'qs'模块,把数据转换一下

    import Qs from 'qs'
    this.$axios
          .post(Api.initCheapOrder, Qs.stringify({name: 'zs'}), {'headers': {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}})  
            .then(res => {
                  .......
            }).catch(e=>{......})
    
    image.png

    相关文章

      网友评论

          本文标题:Axios里POST application/x-www-for

          本文链接:https://www.haomeiwen.com/subject/xpdnaqtx.html