[Vuejs]-How can i order by snapshot's child data containing a timestamp index with vue js

0👍

I don’t use firebase, but it looks like db reference provides orderByKey, so…

let postRef = db.ref('posts').orderByKey('timestamp');

An alternative would be sorting yourself, after retrieval…

this.allPosts = Object.values(val).flatMap(posts =>
    Object.entries(posts).map(([ _key, post ]) => ({ _key, ...post}))
).sort((a, b) => a.timestamp.toMillis() - b.timestamp.toMillis()); 

Leave a comment