In my vue app, I am fetching some data from firebase in the created
-hook.
I want the code afterwards to be exectuted after the data was finished with loading. But I can not make it work.
Here is my code:
<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>
But one the console, first 'Done with fetching Data'
is displayed, then null
(because this.settings
is still null
) and only after that the Objekt settings
is printed.
But I need this.settings
to be defined there (and not null
anymore) to work with there.
What I tried so far:
- Putting in awaits
- Adding a loaded
parameter
- Adding the code afterwards in a
then()
Nothing worked.