欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

axios?POST提交數(shù)據(jù)的三種請求方式寫法示例

 更新時間:2023年09月01日 09:27:54   作者:Awbeci  
這篇文章主要介紹了axios?POST提交數(shù)據(jù)的三種請求方式寫法示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

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,還好現(xiàn)在都搞懂了他們的原理

2、上面三種方式會對應后臺的請求方式,這個也要注意,比如java的@RequestBody,HttpSevletRequest等等

以上就是axios POST提交數(shù)據(jù)的三種請求方式寫法示例的詳細內(nèi)容,更多關于axios POST提交數(shù)據(jù)請求方式的資料請關注腳本之家其它相關文章!

相關文章

最新評論