微信小程序云开发
微信小程序云开发零基础掌握cloud项目实战开发,小程序开发进阶课程,云函数/云数据库/云存储的用法
https://www.bilibili.com/video/BV1MY411Y7Ak/?vd_source=d10c649e248b08f4441d8cd6b76f46fc
P1 1.1.微信小程序云开发介绍与知识点概述
文档 http://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html
有免费体验版
前往免费体验 Serverless 无服务器开发模式。
P2 1.2.云开发的开通及项目初始化
bind:tap="getData" bindtap="getData"
P3 2.1.使用云控制台控制数据库
P4 2.2.在页面展现云数据库的内容
index.js
const db=wx.cloud.database()
Page({
data:{},
getData(){
db.collection('sqltablename').doc('id').get({
success:res=>{
console.log(res)
this.setData({
dataObj:res.data
})
}
})
},
})
P5 2.3.查询指令Collection
db.collection('sqltablename').doc('id').get().then(res=>{
})
db.collection('sqltablename').where({
author:'xx'
}).get().then(res=>{
})
P6 2.4.添加数据到云数据库add
addData(){
db.collection('name').add({
data:{
title:'xx',
xx:xx
}
})
}
P7 2.5.提交表单添加到云数据库
form表单 bindsubmit事件
<button type="primary" form-type="submit">
submit
</button>
P8 2.6.更新云数据库的两种方法update
在app.json 写页面保存 自动创建相关
db.collection('name').update({
data:{
author:'xx'
}
})
不写条件 全部改
doc() where()云函数用 加条件
db.collection('name').doc('id').set({
//set 没写的字段全部没有了
data:{
author:'xx'
}
}).then(res=>{
console.log(res)
})
P9 2.7.删除数据记录及表单是数据收集remove
db.collection('name').doc('id').remove().then(res=>{
})
bindinput
控制台的删除不了
P10 2.8.count个数与watch数据监听
db.collection('name').doc('id').count().then(res=>{
})
watch 监听数据库数据
db.collection('name').watch({
onChange(res){
},
onError(err){}
})
wx:for wx:key
P11 2.9.各项构建查询条件
db.collection('name')
.limit(3)
.skip(3)
.field({
title:true
})
.orderBy('time','asc').get().then(res=>{
})
P12 2.10.command的介绍
const db=wx.cloud.database();
const _=db.command
db.collection().where({
//hits:666
hits:_.eq(666)
hits:_.and(_.gte(0),_.lte(100)) 0-100
}).get().then(res=>{})
db.collection().where(_.or([
{hits:_.lt(300)},
{author:_.eq('koo')}
])).get().then(res=>{})
command 可闷
eq lte lt gt gte in官方文档查询
P13 2.11.command的比较操作符eq/in
P14 2.12.command的逻辑操作符and/or
P15 2.13.command的数组操作符elemMatch/s...
db.collection().where({
time:_.exists(true) //判断字段是否存在
tabs:_.size(3)
tabs:_.all(['x','sx'])
}).get().then(res=>{})
P16 2.14.command更新字段与数组push/pull
db.collection().doc().update({
data:{
title:'x'
hits:_.inc(-6)
time:_.remove()// 删除字段
tabs:_.pull('xx') //pull移出某些
//unshift shift push pop 数组操作
tabs:_.push({
each:['x'],
position:1
})
}
}).then(res=>{})
P17 3.1.云函数基础介绍callFunction
项目 云服务器 右击 新创建node云函数
云函数 右击 创建并部署
修改云服务器 一定要上传部署 俩个都行
server
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
const db=cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
let {age}=event
return await db.collection('name').get()
}
page.js
Page({
onLoad: function (options) {
wx.cloud.callFunction({
name:'getData',
data:{
age:11
}
}).then(res=>{
console.log(res)
})
},
})
P18 3.2.传递数据给云函数
P19 3.3.【小案例】触底加载新数据onReachB...
P20 3.4.【小案例】limit和skip条件筛选数据库
P21 3.5.【小案例】获取实时阅读次数
<view wx:for="{{xx}}"
bindtag="click"
data-id="{{item.id}}"
wx:key="{{index}}">
click(res){
let {id}=res.currentTarget.dataset
}
P22 4.1.微信小程序cloud云存储介绍
wx.cloud.uploadFile
wx.chooseImage
P23 4.2.上传多张图片并存入云存储
P24 4.3.微信小程序云开发基础篇教程总结
inc增加 多用户同时点赞 不覆盖
https://free.modao.cc/app/e718ec969f01850521831202a97a12fe8cab83b0#screen=sBF003479271583807648787

浙公网安备 33010602011771号