您当前的位置: 首页 >  彭世瑜 ios

axios提交post数据

彭世瑜 发布时间:2019-01-10 18:38:15 ,浏览量:3

默认提交payload

以json形式提交

axios.post(url, {key: value}
).then( res => {
    console.log(res)
}).catch( res => {
    console.log(res)
})
提交formdata

如果后端人员比较老派,没法接受json格式,那就给他提交formdata

var fd = new FormData()
fd.append('key', value)
let config = {
    headers: {
        'Content-Type': 'multipart/form-data'
    }
}
axios.post(url, fd, config
).then( res => {
    console.log(res)
}).catch( res => {
    console.log(res)
})

或者使用CDN方式引入



    
    
    
    


    

let url = "http://127.0.0.1"

let data = {
    name: "Tom",
    age: 23
}

// 注意Qs是大写,和npm引入方式不一样
axios.post(url, Qs.stringify(data)).then(res=>{
    console.log(res);
}).catch(err=>{
    console.log(err);
})



参考 axios配置后,post提交formdata

关注
打赏
1688896170
查看更多评论

彭世瑜

暂无认证

  • 3浏览

    0关注

    2727博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0803s