vue-cli使用axios發送post請求,后台獲取不到數據


通過多次查詢並嘗試,找到了兩種結局辦法

方法一:使用qs解決

 npm install qs --save-dev

 在main.js中引入qs

   import qs from 'qs'
  Vue.prototype.$qs = qs

 在.vue文件中使用

let params = {
mobile: that.mobile,
code: that.code
}
that.$ajax.post(that.GLOBAL.url + 'c=members&a=codeLogin', that.$qs.stringify(params))
.then(function (response) {
console.log(response)
})
.catch(function (error) {
console.log(error)
})

方法二:使用URLSearchParams傳遞參數,網上大多數都是這樣的方法

let param = new URLSearchParams()
param.append('mobile', that.mobile)
param.append('code', that.code)

that.$ajax.post(url, param)
.then(function (response) {
that.$emit('hidden')
console.log(response)
})
.catch(function (error) {
console.log(error)
})


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM