Use formData to pass parameters in the post request in vue+axios
1. Introduction qs
.
// 引入qs
import qs from 'qs'
// 引入qs
import qs from 'qs'
2. Set content-type
// content-type
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
// 设置content-type
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}
3. Convert the parametersqs.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. Effect