uniapp云开发
一、新建uniapp云開發(fā)項(xiàng)目
右鍵新建項(xiàng)目,
勾選啟用
二、云服務(wù)空間
如果沒有的話點(diǎn)擊新建
有了云服務(wù)器點(diǎn)擊關(guān)聯(lián)即可
三、云函數(shù)
創(chuàng)建
云函數(shù)的編寫
上傳云函數(shù)
頁面調(diào)用
四、云數(shù)據(jù)庫
創(chuàng)建云數(shù)據(jù)庫
第一次使用新建表在右側(cè)
新增數(shù)據(jù)
表結(jié)構(gòu)
下載表結(jié)構(gòu)(可選)
運(yùn)行項(xiàng)目
連接云函數(shù)
展示數(shù)據(jù)
collection中的內(nèi)容是你的數(shù)據(jù)表名
效果展示
五、數(shù)據(jù)庫的增刪改
增加數(shù)據(jù)
代碼如下
<template><view><uni-easyinput v-model="item.name" placeholder="請(qǐng)輸入用戶名"></uni-easyinput><uni-easyinput v-model="item.tel" placeholder="請(qǐng)輸入手機(jī)號(hào)"></uni-easyinput><button @click="add()">添加</button></view> </template><script>export default {data() {return {item:{name:'',tel:''}}},methods: {add(){//數(shù)據(jù)庫var db = uniCloud.database();//獲取表db.collection("concat")//執(zhí)行添加.add(this.item).then(res=>{uni.showToast({title:"添加成功"})}).catch(err=>{console.log(err)})}}} </script><style></style>刪除數(shù)據(jù)
更改數(shù)據(jù)
update.vue 代碼如下
<template><view><uni-easyinput v-model="item.name" placeholder="請(qǐng)輸入用戶名"></uni-easyinput><uni-easyinput v-model="item.tel" placeholder="請(qǐng)輸入手機(jī)號(hào)"></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();//獲取數(shù)據(jù)庫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表模板創(chuàng)建 數(shù)據(jù)表
例:通訊錄
點(diǎn)擊下載校驗(yàn)函數(shù)
打開下載的通訊錄jison文件
點(diǎn)擊
第一次使用的用戶需下載
自動(dòng)生成頁面
注冊(cè)
合并文件
list.vue文件里的渲染內(nèi)容改為item.username
成功
總結(jié)
- 上一篇: 算法选修(J.琴和可莉)(为选修画上句号
- 下一篇: 中国互联网史最大规模合并案 阿里巴巴全资