收藏
回答

微信小程序 js方法()和If怎么异步?

    get(){ 
        this. getsttag(app.globalData.shitangname) ///查询选择的食堂是否关闭了当日报餐功能
        if (app.globalData.sttag == '1') {
            wx.showToast(
                {     
                  icon:'error',
                  title:'已关闭当日报餐',
                })  
                return
        }else
        {console.log("打印测试获取的数据",'000000')}
}
这个get()在执行的时候,先if判断 后再执行this. getsttag(app.globalData.shitangname),
想要的是先this. getsttag(app.globalData.shitangname) 执行这个后得到结果app.globalData.sttag 的值,再if判断 
帮忙看下怎么异步执行,谢谢
回答关注问题邀请回答
收藏

1 个回答

  • 睡前原谅一切
    睡前原谅一切
    2022-05-05
    async get(){ 
      const res = await this.getsttag(app.globalData.shitangname)
      console.log(res) // 具体你这个会返回啥不清楚,你下面的判断按照你的条件来
      if (res.xxx) {
         if (app.globalData.sttag == '1') {
            return wx.showToast({     
              icon:'error',
              title:'已关闭当日报餐',
            })           
         } else {
          console.log("打印测试获取的数据",'000000')
        }
      }
    }
    


    2022-05-05
    有用 1
    回复 1
    • 轻风
      轻风
      2022-05-05
      谢谢
      2022-05-05
      回复
登录 后发表内容