微信小程序中使用es6-promise.js封装请求与处理异步进程的方法

const Promise = require('es6-promise.min.js')
import {config} from "config.js";
 wxLogin: function () {
    return new Promise((resolve, reject) => {
   const func={
   wx.login({
        success: function (res) {
          resolve(res)
        },
        fail: function (err) {
          console.log(err)
          wx.hideLoading();
          if(err.errMsg == "request:fail timeout"){
            wx.showToast({
              title: '网络请求超时,请稍后再试',
              icon:'none'
            })
          }else if(err.errMsg.indexOf("ERR_NAME_NOT_RESOLVED") > -1){
            wx.showToast({
              title: '网络请求超时,请稍后再试',
              icon: "none"
            })
          }
          reject(err)
        },
        complete: function (res) {
        }
      })
    })
  },
}
module.exports=func

  config.js为请求地址

 

posted @ 2022-08-05 16:48  崛起崛起  阅读(142)  评论(0)    收藏  举报