formDataを使用して、vue + axiosのPOSTリクエストでパラメーターを渡します
1.はじめにqs
。
// 引入qs
import qs from 'qs'
// 引入qs
import qs from 'qs'
2.コンテンツタイプを設定します
// content-type
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
// 设置content-type
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
3.パラメータを変換しますqs.stringify(postPara)
// qs.stringify(postPara)
let postPara = Object.assign(para,{
'access_token': sessionStorage.getItem('token'),})
axios.post(common.url(url), qs.stringify(postPara), config).then(res => {
resolve(res);
}, err => {
reject(err);
}).catch((error) => {
reject(error)
})
4.効果