[英]How to Use Firebase with Nativescript-Vue?
I've been trying to implement just a simple Firebase fetch since November.自 11 月以来,我一直在尝试实现一个简单的 Firebase 获取。 At this point, I wish I'd just created a new Rails api;在这一点上,我希望我刚刚创建了一个新的 Rails api; it would have been faster.它会更快。 But everyone insists Firebase is Oh So Simple.但每个人都坚持 Firebase 非常简单。
In app.js,在 app.js 中,
import firebase from 'nativescript-plugin-firebase';
That part seems OK.那部分似乎还可以。 Instructions are all over the place after that.在那之后,说明到处都是。 The plugin's ReadMe suggests an initialization:该插件的自述文件建议进行初始化:
firebase.init({
// Optionally pass in properties for database, authentication and cloud messaging,
// see their respective docs.
}).then(
function () {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
Several others have insisted that the init code is unnecessary.其他几个人坚持认为 init 代码是不必要的。 It does run without errors, but the code he gives after that produces nothing.它确实运行没有错误,但他之后给出的代码没有产生任何结果。 Also,还,
const db = firebase.firestore;
const UserStatusCollection = db.collection("UserStatus");
UserStatusCollection.get();
produce an empty object {}.产生一个空对象 {}。
Here's my Firebase collection:这是我的 Firebase 集合:
If I wrap the firebase call in async/await (and no one is showing it as this complicated),如果我将 firebase 调用包装在 async/await 中(并且没有人将其显示为如此复杂),
async function getFireStoreData() {
try {
let result = await this.UserStatusCollection.get();
console.log(result);
return result;
}
catch (error) {
console.error(
"UserStatusCollection.get()" + error
);
}
}
And call that并称之为
let temp2 = getFireStoreData();
console.log("temp2:" + temp2);
All I ever get is an object promise.我得到的只是一个对象承诺。
As I said, I wish I had just built up a new Rails API and had a far simpler life since November.正如我所说,我希望我刚刚构建了一个新的 Rails API,并且自 11 月以来的生活要简单得多。
Your getFireStoreData
method is asynchronous and you're not await
ing it.您的getFireStoreData
方法是异步的,您无需await
它。 That is probably the reason why you're getting a promise back.这可能就是你得到承诺的原因。 Try to await getFireStoreData()
.尝试await getFireStoreData()
。 See if that works.看看这是否有效。
Since it's also a promise, you can try to use .then
.既然它也是一个承诺,你可以尝试使用.then
。
getFireStoreData().then(data => {
console.log(data);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.