axios结合面向对象封装

时间:2021-03-03 15:03:54   收藏:0   阅读:42

function CommonAPI(url, getAPIFn, header) {
    this.url = url;
    this.header = header;
    this[getAPIFn] = async (data) => {
      var result = await axios({
        url: this.url,
        method: "post",
        data: data,
        headers: this.header
      }).then((res) => {
        return (res.data)
      }).catch(req => {
        throw req
      })
      return result
    }
  }

原文:https://www.cnblogs.com/hksstwtaugmy/p/14472856.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!