第一步:新建云數(shù)據(jù)庫emall
image.png
第二步: 創(chuàng)建一個按鈕
<button type="primary" bindtap="addmall">添加商品</button>
第三步: 創(chuàng)建addmall函數(shù)
// 獲取云數(shù)據(jù)庫實例
const db = wx.cloud.database()
addmall: function() {
// 顯示消息對話框
// wx.showToast({
// title: '添加',
// })
db.collection('emall').add({
data: {
title: '商品1',
pricce: 23
},
success: function(res) {
console.log(res)
wx.showToast({
title: '新增成功',
})
}
})
}