Axios 封装

可以利用axios的原生请求进行传参序列化调整

axios.fetchData=function(url,params)  //fetchData for post json stringify data
 {
    return  axios.post(url, serializeData(params))
 }; 
 


  function serializeData(data) {
    if (!(data instanceof Object)) {
      return ((data == null) ? "" : data.toString());
    }
    var buffer = [];
    for (var name in data) {
      if (!data.hasOwnProperty(name)) {
        continue;
      }
      var value = data[name];
      if (value instanceof Object) {
        value = JSON.stringify(value);
      }
      buffer.push(
        encodeURIComponent(name) + "=" + encodeURIComponent((value == null) ? "" : value)
      );
    }
    var source = buffer.join("&").replace(/%20/g, "+");
    return (source);
  }

 

Axios 封装

上一篇:MyBatis-Plus Wrapper条件构造器查询大全


下一篇:java基础入门知识大纲(新手必看,从HelloWorld到实现聊天功能的app)