Use formData to pass parameters in the post request in vue+axios

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
Insert picture description here

Guess you like

Origin blog.csdn.net/zcbmwasd/article/details/112845825