axios结合面向对象封装


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
    }
  }
posted @ 2021-03-03 10:09  蓝色星空_hkss  阅读(92)  评论(0编辑  收藏  举报