浅念`

导航

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)//失败
})

posted on 2020-07-13 14:24  浅念`  阅读(14363)  评论(0编辑  收藏  举报