const db = wx.cloud.database();
Page({
data: {
background: [1,2,3],
products: []
},
onLoad: function (options) {
db.collection('products').get({
success: function(r) {
console.log(r)
this.data.products = r
console.log(this.data.products)
}
})
}
})
上面console.log(r)可顯示資料,但賦值後console.log(this.data.products)就沒有相關資料,到底是什麼問題?
onLoad: function (options) { const that = this; db.collection('products').get({ success: function(res) { console.log(res) that.setData({ products: res.data }) console.log(that.data.products) } }) }