vue开发入门-axios POST提交数据的三种请求方式写法


1、Content-Type: application/json

let data = {"code":"1234","name":"yyyy"}; axios.post(`${this.$url}/test/testRequest`,data) .then(res=>{ console.log('res=>',res); })

 

 

2、Content-Type: multipart/form-data

let data = new FormData(); data.append('code','1234'); data.append('name','yyyy'); axios.post(`${this.$url}/test/testRequest`,data) .then(res=>{ console.log('res=>',res); })

 

 

3、Content-Type: application/x-www-form-urlencoded

import axios from 'axios' import qs from 'Qs' let data = {"code":"1234","name":"yyyy"}; axios.post(`${this.$url}/test/testRequest`,qs.stringify({ data })) .then(res=>{ console.log('res=>',res); })

post上传的三种content-type类型详解可以查看:https://blog.csdn.net/u014209205/article/details/81147783
本篇博客转至:https://segmentfault.com/a/1190000015261229


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM