Promise封装request请求<微信小程序>

/**

  • path请求地址
  • params请求参数
  • method请求方法
  • */
    const HOST = 'url';
    module.exports = (path, params,token, method = 'POST') => {
    let URL = path.includes('https//') ? path : ${HOST}/${path};
    return new Promise((resolve, reject) => {
    wx.request({
    url: URL,
    method: method,
    data: Object.assign({}, params),
    dataType: 'json',
    header: { 'content-type': 'application/json', 'token': token},
    success: resolve,
    fail: reject
    })
    })
    }

你可能感兴趣的:(Promise封装request请求<微信小程序>)