【发布时间】:2021-04-15 18:39:52
【问题描述】:
在我的 vue 应用程序中,我从 created-hook 中的 firebase 获取一些数据。
我希望在数据加载完成后执行代码。但我不能让它工作。
这是我的代码:
<template>
<div>
<h1>Test 2</h1>
</div>
</template>
<script>
import { institutesCollection } from '../firebase';
export default {
name: 'Test2',
data() {
return {
settings: null,
}
},
async created() {
await institutesCollection.doc('FbdYJ5FzQ0QVcQEk1KOU').onSnapshot(
await function(doc) {
this.settings = doc.data();
console.log(this.settings);
}
)
console.log('Done with fetching Data');
console.log(this.settings)
},
methods: {
}
}
</script>
但是在控制台中,首先显示'Done with fetching Data',然后显示null(因为this.settings 仍然是null),然后才打印Objekt settings。
但我需要在那里定义this.settings(不再是null)才能在那里工作。
到目前为止我尝试了什么:
- 等待加入
- 添加已加载的
parameter - 之后在
then()中添加代码
没有任何效果。
【问题讨论】:
标签: javascript firebase vue.js google-cloud-firestore vuejs2