p8-uniCloud实战通讯录-新增联系人

94 阅读1分钟

新增功能演示

添加功能代码

<template>
	<view>
		<uni-easyinput v-model="item.name" placeholder="name"></uni-easyinput>
		<uni-easyinput v-model="item.phone" placeholder="phone"></uni-easyinput>
		<button type="default" @click="submit">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				item: {
					"name": "",
					"phone": ""
				}
			}
		},
		methods: {
			submit() {
				const db = uniCloud.database();
				db.collection('contacts').add(this.item).then(
					e=> {
						console.log(e)
					}
				)
			}
		}
	}
</script>

  • 点击添加之后,刷新主页,添加成功