function getPromise(url, method = "GET", data = {}, header = {}) {
return new Promise((resolve, reject) => {
wx.request({
url: url,
header: header,
success: function (res) {
resolve(res)
},
fail: function (res) {
reject(res)
},
method: method,
data: data,
dataType: "json"
})
})
}
is encapsulated as above;
is called as follows
getPromise(_url, "POST", _data)
.then((res) => {
})
is called as above, but what if multiple requests are nested within each other?
getPromise(_url, "POST", _data)
.then((res) => {
getPromise(_url, "POST", _data)
.then((res) => {
...
})
})