export const request = (url, method = "GET", data) => {
  let _url = `${baseUrlPrefix}${url}`;

  return new Promise((resolve, reject) => {
    Taro.showLoading({
      title: "正在加载"
    });
    Taro.request({
      url: _url,
      data: data,
      method: method,
      header: {
        "content-type": "application/json"
      },
      success: res => {
        console.log("从接口获取到的数据", res);
        let { code } = res.data;
        Taro.hideLoading();
        if (code === 200) {
          resolve(res.data.data);
          wx.hideLoading();
        } else {
          wx.showToast({
            title: "数据请求错误"
          });
        }
      },
      fail() {
        reject("接口有误,请检查");
      }
    });
  });
};

相关文章:

  • 2021-08-25
  • 2021-12-18
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-06-16
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案