axios發送post請求,提交表單數據


解決辦法一

你要是看下用法就解決了。。。
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
        })

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM