1. 程式人生 > >axios post請求,傳遞引數,後臺接收不到資料

axios post請求,傳遞引數,後臺接收不到資料

post請求與get請求傳遞引數的方式不太一樣

post請求:(get中的引數可以直接以鍵值對的形式,post中需要將鍵值對轉換成query)

import Qs from 'qs'  //可直接引入,axios中已經包含
var url = '/api/user/registe' 
//轉換成query
var data = Qs.stringify({
'studentid': this.regNum,
'username': this.regName, 
'userpassword': this.regPassword})

this.axios.post(url, data)
.then((result) => {
var resData = result.data
console.log(resData)
if (resData.status === 1) {
//請求成功後執行的方法
} else {
//請求失敗後執行的方法
}
})
.catch(function (error) {
console.log(error)
})