在onload里面写查数据库,查询结果却在onready之后,求大佬讲解一下
发布于 5 年前 作者 ayu 7592 次浏览 来自 问答

如下图所示,在onload里写的查数据库的方法,却在onready之后打印出结果

具体方法如下:

  onLoad:function(options){

    this.searchInfo()

  },

searchInfo:function(){

    console.log(“onshow…”)

    const db = wx.cloud.database()

    console.log(“onshow111”)

    db.collection(‘problem’).where({

      _openid: this.data.openid,

    }).get({

      success: res => {

        this.setData({

          items: JSON.stringify(res.data, null, 2)

        })

        console.log(“123:”, this.data.items)

      },

      fail: err => {

        wx.showToast({

          icon: ‘none’,

          title: ‘查询记录失败’

        })

      }

    })

  }

1 回复

查询结果异步操作  需要一定的时间的

回到顶部