1、在index.js里设置
const db=wx.cloud.database({
env:"environmentlyl-7g8m55cjcacc768c"
})/* 连接数据库*/
data: {
dataObj:""
},
getData(){
db.collection("demolist") .get({
success:res=>{
console.log(res)
this.setData({
dataObj:res.data
})
}
})/*拿哪个数据*/
},
2、index.wxml
<button type="primary" bindtap="getData">点击获取数据</button>
<view wx:for="{{dataObj}}">{{item.title}} - {{item.author}}</view>
3、查询数据
已知id,用.doc查询即可
已知其他项,用.where
db.collection("demolist") .where({
author:"美羊羊"
}).get()
.then(res=>{
console.log(res)
})
db.collection("demolist") .doc("1551b00560361915000190b837d48b8a")
.get()
.then(res=>{
console.log(res)
})