7***@qq.com
7***@qq.com
  • 发布:2024-01-30 21:37
  • 更新:2024-01-30 22:21
  • 阅读:208

云函数返回值为undefined

分类:uniCloud

为什么调用云函数测试返回值为undefined??调用之后立即返回undefined,不会等待setTimeout执行

                let todata = {  
                    conid: '65a204aa337asdfsdfe79'  
                }  
                uniCloud.callFunction({  
                    name: 'ceshi',  
                    data: todata  
                }).then(res => {  
                    console.log(res);  
                }).catch(err => {  
                    console.log(err);  
                })
'use strict';  
exports.main = async (event, context) => {  
    //event为客户端上传的参数  
    console.log('event : ', event)  
    setTimeout(() => {  
        let redata = event  
        console.log(redata);  
        return redata  
    }, 2000);  
};
2024-01-30 21:37 负责人:无 分享
已邀请:
喜欢技术的前端

喜欢技术的前端 - QQ---445849201

可以换个写法

'use strict';  
const db = uniCloud.database()  
let resultFun = (event) => {  
    return new Promise((resolve, reject) => {  
        setTimeout(() => {  
            let redata = event  
            resolve(redata)   
        }, 2000);  
    })  
}  
exports.main = async (event, context) => {  
    // event为客户端上传的参数    
    console.log('event : ', event)  
    let res = await resultFun(event)  
    return res  
};

要回复问题请先登录注册