I am attempting to get my app to render my data in an array from Firestore in SSR using asyncData. My function outside of asyncData is working fine but I can NOT get it to work inside.
I have tried so many ways of getting the array from asyncData to render. I trying to return the data onto 'addons' so it fills out the form the same way my method does.
Here is my working method
async getAddons() {
var addonsRef = db
.collection('addons')
.where('publish', '==', true)
.orderBy('timeUpdated', 'desc');
await addonsRef.get().then(snapshot => {
snapshot.forEach(doc => {
const addons = {
...doc.data(),
id: doc.id
};
return this.addons.push(addons);
});
});
},
And here is the code I am currently trying inside asyncData
async asyncData({ app, error }) {
const addonsRef = await db
.collection('addons')
.where('publish', '==', true)
.orderBy('timeUpdated', 'desc');
try {
await addonsRef.get().then(snapshot => {
snapshot.forEach(doc => {
const addons = {
...doc.data(),
id: doc.id
};
return app.addons.push(addons);
});
});
} catch (e) {
// TODO: error handling
console.error(e);
}
return app.addons.push(addons);
},
I expect the asyncData code to populate the array so it fills out my template the same as the getAddons function.
What simple thing am I missing?