您的位置:首页 > 移动开发 > IOS开发

axios发送post请求,提交表单数据

2018-03-14 14:08 741 查看

解决办法一

你要是看下用法就解决了。。。

https://www.npmjs.com/package

或者

https://github.com/mzabriskie

axios({
url: '/user',
method: 'post',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
},
transformRequest: [function (data) {
// Do whatever you want to transform the data
let ret = ''
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
return ret
}],
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})


解决办法二

使用qs这个类库



this.$axios
.post(
'/user/login',
this.$qs.stringify({
login_account: this.loginForm.username,

password: this.loginForm.password,

remark: this.checked === true ? 'autologin' : 'nocheck'
})
)
.then(function(response) {
console.log('login success')
console.log(response)
this.loading = false
localSt
4000
orage.setItem('ms_username', this.loginForm.username)
this.$router.push('/home')
})
.catch(() => {
this.loading = false
})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: