您好,欢迎来到纷纭教育。
搜索
您的当前位置:首页在vue中使用axios发送post请求,参数方式

在vue中使用axios发送post请求,参数方式

来源:纷纭教育

 由于后台接收的参数格式为FormData格式

在axios中参数格式默认为

在传参数前,将原先官方提供的格式

改为如下:

axios({
  url: '../../../room/listRoomPage',
  method: 'post',
  data: {offset: 0, limit: 9999, roomCode: "", roomtypeId: 0, floorId: 0},
  transformRequest: [function (data) {
    var oMyForm = new FormData();
    oMyForm.append("offset", 0);
    oMyForm.append("limit", 9999);
    oMyForm.append("roomCode", "");
    oMyForm.append("roomtypeId", 0);
    oMyForm.append("floorId", 0);
    console.info(oMyForm);
    return oMyForm;
  }],
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
})
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

成功得到后台返回的数据

 

转载于:https://www.cnblogs.com/ryans/p/7383813.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- fenyunshixun.cn 版权所有 湘ICP备2023022495号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务