uniapp云开发
一、新建uniapp云開發項目
右鍵新建項目,
勾選啟用
二、云服務空間
如果沒有的話點擊新建
有了云服務器點擊關聯即可
三、云函數
創建
云函數的編寫
上傳云函數
頁面調用
四、云數據庫
創建云數據庫
第一次使用新建表在右側
新增數據
表結構
下載表結構(可選)
運行項目
連接云函數
展示數據
collection中的內容是你的數據表名
效果展示
五、數據庫的增刪改
增加數據
代碼如下
<template><view><uni-easyinput v-model="item.name" placeholder="請輸入用戶名"></uni-easyinput><uni-easyinput v-model="item.tel" placeholder="請輸入手機號"></uni-easyinput><button @click="add()">添加</button></view> </template><script>export default {data() {return {item:{name:'',tel:''}}},methods: {add(){//數據庫var db = uniCloud.database();//獲取表db.collection("concat")//執行添加.add(this.item).then(res=>{uni.showToast({title:"添加成功"})}).catch(err=>{console.log(err)})}}} </script><style></style>刪除數據
更改數據
update.vue 代碼如下
<template><view><uni-easyinput v-model="item.name" placeholder="請輸入用戶名"></uni-easyinput><uni-easyinput v-model="item.tel" placeholder="請輸入手機號"></uni-easyinput><button @click="update()">更新</button></view> </template><script>export default {data() {return {item:{name:'',tel:''}}},onLoad(option) {this.item = JSON.parse(option.item)},methods: {update(){//獲取itemvar item = {...this.item};delete item._id;const db = uniCloud.database();//獲取數據庫db.collection("concat").doc(this.item._id)//查詢一條.update(item).then(res=>{uni.showToast({title:"更新成功"})uni.navigateBack();}).catch(err=>{console.log(err)})}}} </script><style></style>六、使用OpenDB表模板創建 數據表
例:通訊錄
點擊下載校驗函數
打開下載的通訊錄jison文件
點擊
第一次使用的用戶需下載
自動生成頁面
注冊
合并文件
list.vue文件里的渲染內容改為item.username
成功
總結
- 上一篇: 算法选修(J.琴和可莉)(为选修画上句号
- 下一篇: 中国互联网史最大规模合并案 阿里巴巴全资