欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

axios POST提交数据的三种请求方式写法

程序员文章站 2022-04-14 22:41:45
...

1、Content-Type: application/json      ==> @RequestBody

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

2、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);            
})

3、Content-Type: multipart/form-data

import axios from 'axios'
let data = new FormData();
data.append('code','6352');
data.append('name','kelly');
axios.post(`${this.$url}/test/testRequest`,data)
.then(res=>{
    console.log('res=>',res);            
})
相关标签: POST