this is encapsulated
function request(url, params) {
let promise = new Promise(function (resolve, reject) {
wx.request({
url: url,
data: params,
header: {
"X-Token-With": token
},
method: "POST",
success: function (res) {
console.log(params)
console.log(res)
app.globalData.netWorkData = res.data
resolve();
}
})
});
return promise
}
request with encapsulation method
let data = { keyword: city_name }
let url = `${app.globalData.baseUrl}/city/city`
network.request(url,data).then(() => {
_this.setData({
// hot_city: _this.jsonToArray(app.globalData.netWorkData.resultData)
city: {
name: city_name,
id: app.globalData.netWorkData.resultData[0].region_id
}
})
});
Why is it different? what"s the problem?