Vue:axios中POST请求传参问题

vue的ajax请求用的是axios组件,结果在用到post请求的时候,发现给后台传data时,后台(python语言+django框架)接收不到。vue

后台的request.body显示出,我给传送的是data被django打包成了一个obj中的key值,value为空数组。致使后台获取不到。python

解决方案:ios

axios({
    method:'POST',
    url:ap_service_url+opt.url,
    data:opt.obj,
    transformRequest: [function (data) {
            let ret = ''
            for (let it in data) {
                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
            }
            return ret
        }],
    headers:{'Content-Type': "application/x-www-form-urlencoded"}
}).then(function(res){
      /*请求成功*/
}).catch(function(err){
       /*请求失败*/
})

经过添加transformRequset成功跳出这个坑~ajax

相关文章
相关标签/搜索