vue 集成axios之后,发送的post请求默认为payload 方式。 如果想改为正常的方式,需要增加headers头,并且将发送是数据json格式改为 querystring的方式。

安装依赖

cnpm install qs

 

导入依赖

import Qs from 'qs'

 

在需要使用post的地方使用下面的方法,其中postData是一个json对象

this.$http({
    url: '/api/act/yourApi.api',
    method: 'POST',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    data: Qs.stringify(postData)
})
    .then(res => {
        console.log(res);
    })
    .catch(err => {
        console.log(err);
    })

这样,发送的数据就是以 form-urlencodoed的方式发送了。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-18
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案