还有 change 和 before 可以使用这里列出的方法:https://firebase.google.com/docs/参考/admin/node/admin.database.DataSnapshotI have some cloud functionsbut they suddenly stopped working, now I'm getting event.data undefinedexports.newMessageReceived = functions.database.ref('/messages/{pushId}') .onWrite((event) => { if (event.data.previous.exists() || !event.data.exists() ) { //Do nothing if data is edited or deleted console.log('Message edited or deleted - skip'); return; } ...}And I getTypeError: Cannot read property 'previous' of undefinedThis is how it is defined here. There was any change in firebase cloud functions? 解决方案 Cloud functions were updated to version 1.0, you can check here for more info:https://firebase.google.com/docs/functions/beta-v1-diff#realtime-databaseRegarding the question, you need to change the code into this:exports.newMessageReceived = functions.database.ref('/messages/{pushId}').onWrite((change,context) => {if (change.before.exists() || !change.after.exists() ) { //Do nothing if data is edited or deleted console.log('Message edited or deleted - skip'); return; }}onWrite now has two parameters change and context. Change has before and after properties, and before is equivalent to previousAlso change and before can use the methods listed here:https://firebase.google.com/docs/reference/admin/node/admin.database.DataSnapshot 这篇关于Firebase 云函数停止工作 - event.data 未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-24 14:15