腾讯云调用云函数会重复添加的bug,如何处理比较好?

- 发布:2020-06-02 17:34
- 更新:2020-06-03 21:23
- 阅读:1192
腾讯云调用云函数会重复添加的bug,如何处理比较好

云筱易 (作者) - 云筱易
//客户端
<template>
<view>
<view class="">
<view class="">标题</view>
<input class="bor" type="text" v-model="title" />
</view>
<view class="">
<view class="">内容</view>
<input class="bor" type="text" v-model="content" />
</view>
<button type="default" @click="tj">提交</button>
</view>
</template>
<script>
export default {
data() {
return {
title:"",
content:""
}
},
methods: {
tj(){
uniCloud.callFunction({
name:'ez_notice',
data:{
title:this.title,
content:this.content
}
}).then(res=>{console.log('res',res)})
}
}
}
</script>
<style>
.bor{
border: #333333 solid 3rpx;
background-color: #fafafa;
}
</style>
//云函数
'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
const collection = db.collection('notice')
let res =await collection.add(event)
return res
};
//执行结果
_id
75777da85ed637da0029203a758d41cc
content
使用腾讯云执行数据库添加操作,云函数会被无故执行两次,在客户端onshow里面也会被无故调用两次云函数
title
bug反馈
//以下部分是多出的. 如果在云函数中添加固有值,比如event.time = 2020-06-02 ,则此时间会单独多出来.
_id
baada3ac5ed637df0034332b28bb286b

云筱易 (作者) - 云筱易
代码详见附件
云筱易 (作者)
//客户端
标题内容提交 export default { data() { return { title:"", content:"" } }, methods: { tj(){ uniCloud.callFunction({ name:'ez_notice', data:{ title:this.title, content:this.content } }).then(res=>{console.log('res',res)}) } } } .bor{ border: #333333 solid 3rpx; background-color: #fafafa; }
//云函数
'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
const collection = db.collection('notice')
let res =await collection.add(event)
return res
};
//执行结果
_id
75777da85ed637da0029203a758d41cc
content
使用腾讯云执行数据库添加操作,云函数会被无故执行两次,在客户端onshow里面也会被无故调用两次云函数
title
bug反馈
//以下部分是多出的. 如果在云函数中添加固有值,比如event.time = 2020-06-02 ,则此时间会单独多出来.
_id
baada3ac5ed637df0034332b28bb286b
2020-06-03 09:15