首页 > 移动平台 > 详细

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

时间:2018-12-19 14:34:52      阅读:137      评论:0      收藏:0      [点我收藏+]

解决办法一

你要是看下用法就解决了。。。
https://www.npmjs.com/package
或者
https://github.com/mzabriskie

 1         axios({
 2             url: ‘/user‘,
 3             method: ‘post‘,
 4             data: {
 5                 firstName: ‘Fred‘,
 6                 lastName: ‘Flintstone‘
 7             },
 8             transformRequest: [function(data) {
 9 
10                 let ret = ‘‘
11                 for(let it in data) {
12                     ret += encodeURIComponent(it) + ‘=‘ + encodeURIComponent(data[it]) + ‘&‘
13                 }
14                 return ret
15             }],
16             headers: {
17                 ‘Content-Type‘: ‘application/x-www-form-urlencoded‘
18             }
19         })

解决办法二

使用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 localStorage.setItem(‘ms_username‘, this.loginForm.username); 
            this.$router.push(‘/home‘);
        }).catch(() => {
            this.loading = false
        })

 

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

原文:https://www.cnblogs.com/jszhp/p/10142904.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!