axios请求中post传参方式

1.使用new URLSeachParams()
let param = new URLsearchParams
//定义参数,几个参数就写几个param.append()
param.append("startTime","2020-6-23 19:10:14")//开始时间
param.append("endTime","2020-6-24 19:08:12")//结束时间
param.append("shreshold","75")//过滤
//post发起请求
axios.post('http://********/****/***',param).then(function(response){
      console.log(response)//成功
})
.catch(function(error){
      console.log(error)//失败
})
如果后端给定发送数据必须是JSON字符串,则不能使用;
2.转义成JSON
let params = {
      startTime:"2020-6-23 19:10:14",//开始时间
      endTime:"2020-6-24 19:08:12",//结束时间
      threshold: "75"//过滤
};
let vm = this;
axios.post(
      "http://********/***/**",
      JSON.stringify(params)
)
.then(function(response){
      console.log(response)//成功
})
.catch(function(error){
      console.log(error)//失败
})
所触及过的星空,哪怕牺牲所有,也竭力想要抵达的地方!
原文地址:https://www.cnblogs.com/lishaoxiong/p/13293005.html