微信小程序promise封装(2)

封装

// 封装请求
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.request = void 0;

var e = function(e) {
    return e && e.__esModule ? e : {
      default: e
    };
  }(require("./es6-promise.min")),
  t = exports.request = function() {
    var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "GET";
    return function(n, r) {
      return new e.default(function(e, u) {
        wx.request({
          url: n,
          data: r,
          method: t,
          header: {
            "Content-Type": "application/json"
          },
          success: function(t) {
            e(t);
          },
          fail: function(e) {
            u(e);
          }
        });
      });
    };
  },
  n = t("GET"),
  r = t("POST"),
  u = t("PUT"),
  o = t("DELETE");

module.exports = {
  get: n,
  post: r,
  put: u,
  del: o
};

引用

const util = require('../utils/promise.js')
const base = 'https://example.com/api';

export const getlist = params => {
  return util.get(`${base}/getlist`,params).then(res=>res.data);
};

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注