云筱易
云筱易
  • 发布:2020-06-02 17:34
  • 更新:2020-06-03 21:23
  • 阅读:1192

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

分类:uniCloud

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

2020-06-02 17:34 负责人:DCloud_uniCloud_WYQ 分享
已邀请:
DCloud_UNI_CHB

DCloud_UNI_CHB

问题描述再具体一些,重复添加什么了,代码示例列出来。

  • 云筱易 (作者)

    //客户端


    标题内容提交 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

云筱易

云筱易 (作者) - 云筱易

//客户端
<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

DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

看起来跟云函数没有关系,发个工程demo上来我看下

  • 云筱易 (作者)

    请在底部下载附件查看

    2020-06-03 21:23

云筱易

云筱易 (作者) - 云筱易

代码详见附件

  • DCloud_uniCloud_WYQ

    使用你这个demo没出现你说的问题,你是运行到了哪端?换个设备还能复现吗?fabu页面的tj方法里面写个console看下有没有重复输出

    2020-06-04 16:19

  • 云筱易 (作者)

    我运行在H5端的,第二条的重复数据需要等待约2秒后才会添加成功

    2020-06-04 23:54

  • DCloud_uniCloud_WYQ

    回复 云筱易: fabu页面的tj方法里面写个console看下有没有重复输出

    2020-06-08 14:05

  • 云筱易 (作者)

    回复 DCloud_uniCloud_WYQ: console打印出来没有重复输出,只有预期结果的一条数据.但是云函数增加了两条数据

    2020-06-08 15:51

  • DCloud_uniCloud_WYQ

    回复 云筱易: 我的QQ:2292434668,加我一下,我这复现不了,远程看一下

    2020-06-08 17:54

  • 云筱易 (作者)

    回复 DCloud_uniCloud_WYQ: 已发送好友验证

    2020-06-08 21:19

该问题目前已经被锁定, 无法添加新回复