axios|axios 遇到后台接收不到参数情况

* 针对当前后台接口实现(遇到后台接收不到参数情况),前端axios请求有三种方法(以登录为例)
* 方法1: 创建formData对象,直接向后台传form

let form = new FormData()
form.append('password', this.password)
form.append('username', this.mobile)
form.append('pcode', pcode)
form.append('devicekey', 'ama1yfrwkx73uhht')
form.append('apptype', 'web')
form.append('appid', 'sixone')
form.append('wt', 'json')
form.append('action', 'login')
req.post(urls.login, form).then(res => { // do something })
* 方法2: 设置header的content-type为application/x-www-form-urlencoded,引入qs,stringify转换参数后传参
import QS from 'qs'
let params = Qs.stringify({
password: this.password,
username: this.mobile,
pcode,
devicekey: 'ama1yfrwkx73uhht',
apptype: 'web',
appid: 'sixone',
wt: 'json',
action: 'login'
})
let headers = {'Content-type': 'application/x-www-form-urlencoded'}
req.post(urls.login, params, headers).then(res => { // do something })
* 方法3: 创建URLSearchParams对象,直接向后台传参
let params = new URLSearchParams();
params.append('password', this.password)
params.append('username', this.mobile)
params.append('pcode', pcode)
params.append('devicekey', 'ama1yfrwkx73uhht')
params.append('apptype', 'web')
params.append('appid', 'sixone')
params.append('wt', 'json')
params.append('action', 'login')
【axios|axios 遇到后台接收不到参数情况】req.post(urls.login, params).then(res => { // do something })

    推荐阅读