微信小程序,将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})});},