小程序做判断时数据还未读入,导致先显示值为空时的页面,然后再显示有值时的页面,请问该如何解决?
代码如下:
wxml:
<view wx:if="{{info.length != 0}}">
<view wx:for="{{info}}">
<view>用户ID: {{item._openid}}</view>
<view>
<view wx:else>
<text style="text-align:center">暂无用户</text>
</view>
js:
data: {
info: [],
}
onLoad: function (options) {
let that = this
let db = wx.cloud.database()
db.collection("userInfo").get().then(res=>{
that.setData({
info: res.data
})
})
},