听起来你只是想
read data once
,你可以用它
get()
这样地:
function getData(target) {
const reference = ref(db, `${target}/`);
return get(reference).then((snapshot) => {
if (snapshot.exists()) {
return snapshot.val();
}
// TODO: what do you want to return when the snapshot does *not* exist?
});
}
或者
async
/
await
async function getData(target) {
const reference = ref(db, `${target}/`);
const snapshot = get(reference);
if (snapshot.exists()) {
return snapshot.val();
}
// TODO: what do you want to return when the snapshot does *not* exist?
}