微信小程序:封装全局的promise异步调用方法
一:封装
function POST(url, params) { let promise = new Promise(function (resolve, reject) { wx.request({ url: url, data: params, method: 'POST', success: function (res) { resolve(res.data); } }) }); return promise }
二:调用
const network = require('../../utils/util.js') network.GET(url, params).then((res) => { //请求成功的操作 console.log(res) });