axios?POST提交數據的三種請求方式寫法示例
更新時間:2023年09月01日 09:27:54 作者:Awbeci
這篇文章主要介紹了axios?POST提交數據的三種請求方式寫法示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
1、Content-Type: application/json
import axios from 'axios'
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
import axios from 'axios'
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);
})
總結
1、從jquery轉到axios最難忘的就是要設置Content-Type,還好現在都搞懂了他們的原理
2、上面三種方式會對應后臺的請求方式,這個也要注意,比如java的@RequestBody,HttpSevletRequest等等
以上就是axios POST提交數據的三種請求方式寫法示例的詳細內容,更多關于axios POST提交數據請求方式的資料請關注腳本之家其它相關文章!
相關文章
javascript中的__defineGetter__和__defineSetter__介紹
這篇文章主要介紹了javascript中的__defineGetter__和__defineSetter__介紹,類似面向對象語言中的get和set關鍵字,需要的朋友可以參考下2014-08-08
JavaScript 實現的 zip 壓縮和解壓縮工具包Zip.js使用詳解
今天給大家介紹的文章是js實現的解壓縮插件zip.js,非常的簡單實用,有需要的小伙伴可以參考下。2015-12-12

