count: (获取记录的条数)
<button type="primary" bindtap="btnNum">查询个数</button>
btnNum() {
db.collection("demoUser").count()
.then(res => {
console.log(res);
})
},
watch监听事件
getData() {
db.collection("demoUser")
.get()
.then(res => {
this.setData({
dataArr:res.data
})
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getData();
db.collection("demoUser").watch({
onChange:res => {
console.log(res)
},
onError:err => {
console.log(err)
}
})
},
<view wx:for="{{dataArr}}" wx:key="index">{{index + 1}}.{{item.title}}</view>
删除后立即显示,点赞功能,接受任务功能
onLoad: function (options) {
this.getData();
db.collection("demoUser").watch({
onChange:res => {
this.setData({
dataArr:res.docs // *
})
},
onError:err => {
console.log(err)
}
})
},