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