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)
})
posted @ 2019-03-28 17:58  qijiamin  阅读(1931)  评论(0编辑  收藏  举报