云开发小程序中await async的写法
~~
云开发小程序中await async的写法
,
其实在开发中,我一直是使用then回调的方式接收云开发集合中的数据,从来没有使用await写法,今天在看掘金某个文章的审核,突然看到这块代码,遂做下总结
~~
async onLoad() {
this.proData() //获取推荐数据项
this.shoeData() //获取鞋类数据项
},
proData() {
const {data} = await dewuCollection
.where({
amway: db.command.eq('TRUE')
})
.field({ //获取指定数据项,提升性能
_id:true,
pic:true,
title:true,
buyer:true,
price:true
})
.get()
// console.log(data);
this.setData({
produces: data,
})
}
shoeData() {
let data1 = await dewuCollection
.where({
type: 1
})
.get()
// console.log(data1.data);
this.setData({
shoes: data1.data
})
}
~~
参考文章

