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

解决办法一

你要是看下用法就解决了。。。
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这个类库
axios发送post请求,提交表单数据_第1张图片

   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
            })

你可能感兴趣的:(vue.js)