axios.post 配置formdata提交

// 方式 一
var
data = new FormData() data.append('username', this.form.username) let config = { headers: { 'Content-Type': 'multipart/form-data' } } axios.post('', data,config).then( res => { console.log(res) }).catch( res => { console.log(res) })

// 方式 二
import qs from 'qs';
let config = {
    headers: {
        'Content-Type': 'multipart/form-data'
    }
}
const data = qs.stringfy({username: 'test'}) axios.post('', data,config).then( res => { console.log(res) }).catch( res => { console.log(res) })
 
原文地址:https://www.cnblogs.com/zhangrenjie/p/14097645.html