promise 封装http请求

 今天研究了一下同事封装的http请求,用的是promise。然后我就研究了下。

 大结构是:

   const fetch=(url, data={},config={})=>{
     let params=Object.assign({}, data);
     config.headers=Object.assign({}, config.headers ,{"Content-Type":"application/json","Access-Control-Allow-Origin":"*"});
     config.body=JSON.stringify(params)
  }

  

猜你喜欢

转载自www.cnblogs.com/artimis/p/10725689.html