微信小程序,将wx.request请求设置为同步,等待其执行结果:
forholiday(){var that = this;return new Promise(function(resolve,reject){wx.request({url: 'http://...', method: 'GET',success: (res) => {resolve(res) },fail(err){}})})},forweekend(){var that = this;return new Promise(function(resolve,reject){wx.request({url: 'https://....', method: 'GET',success: (res) => {resolve(res.data.data.list) },fail(err){reject(err)}})})},holidayInit: async function(){await this.forweekend().then((res) =>{this.setData({weekend: res,workday: true})});await this.forholiday().then((res) =>{this.setData({holiday: res})});},
如果觉得《微信小程序 wx.request转同步》对你有帮助,请点赞、收藏,并留下你的观点哦!