微信小程序云开发------评论的实现
APP.js程序代码:
App({ onLaunch: function () { wx.cloud.init({ env: 'k800c1-f3a89a', // 前往云开发控制台获取环境id,如果使用默认环境则不需要填写 traceUser: true }); }, });
formsubnit.js的代码
程序代码:
// client/pages/formsubnit/formsubnit.js var app=getApp() Page({ /** * 页面的初始数据 */ data: { csid:'', test:'测试', gggs:'', mge:'', name:['袁振诺'] }, formsubnit:function(e){ var shuzhi = e.detail.value.input var oneshuzhi = e.detail.value.oneinput const db = wx.cloud.database() db.collection('test').add({ data: { gggs: oneshuzhi , test: shuzhi }, success:res=>{ this.setData({ csid:res._id, gggs: oneshuzhi, test:shuzhi }) wx.showToast({ title: '新增记录成功', }) console.log('数据库成功新增记录ID:', res._id) }, fail:err=>{ wx.showToast({ icon:'nome', title: '新增记录失败', }) console.error("新增记录失败:",err) } }) }, onQNRJY:function(){ const db = wx.cloud.database() db.collection('test').doc("XH9EqMDR1TiNuMNz").get({ success:res=>{ this.setData({ queryResuit: JSON.stringify(res.data.test[0]), queryTesuit: JSON.stringify(res.data.test[1], null, 2), queryAesuit: JSON.stringify(res.data.test[2], null, 2) }) console.log("数据查询成功",res) }, fail: err => { wx.showToast({ icon: 'nome', title: '查询记录失败', }) console.error("查询记录失败:", err) } }) } })
程序代码:
<!--有什么不懂在我微博下留言,我的微博名《袁振诺》--> <text>client/pages/formsubnit/formsubnit.wxml</text> <form bindsubmit='formsubnit' bindreset='formreset'> <view class='section'> <view class='weui-crlis-title'>数据库插入</view> <view class='weui-crlis-input'><input class='weul-input' name='input' placeholder="输入同步到view中" /></view> <view class='weui-crlis-input'><input class='weul-input' name='oneinput' placeholder="输入同步到view中" /></view> </view> <button form-type='submit'>写入</button> <button bindtap='onQNRJY'>查询</button> <button bindtap='onapp'> 更新</button> <button bindtap='onVict'>删除</button> <scroll-view scroll-y class='Uiopen' > <view><text class='code' wx:if='{{queryResuit}}' >{{name}}:{{queryResuit}}</text></view> <view><text class='code' wx:if='{{queryTesuit}}' >周杰伦:{{queryTesuit}}</text></view> <view><text class='code' wx:if='{{queryAesuit}}' >林俊杰 :{{queryAesuit}}</text></view> </scroll-view> </form>
有什么不懂在我微博下留言,我的微博名《袁振诺》