Answer the question
In order to leave comments, you need to log in
How to get object id from firebase?
Hello. Question from a newbie to Vue. I decided to attach it to my firebase test project here. I want to make an impromptu news feed.
We click on the news - we open the news component with the required ID (using route).
And here is the question of how to correctly generate this news ID.
Now everything works for me like this (I use vuex)
let db = fb.database()
let refBlogs = db.ref('blogs')
class BlogElement {
constructor (name, description, id = null) {
this.name = name
this.description = description
this.id = id
}
}
mutations: {
createBlogElement (state, payload) {
state.blog.push(payload)
const blogElement = new BlogElement(payload.name, payload.description)
refBlogs.push(blogElement)
}
}
Answer the question
In order to leave comments, you need to log in
refBlogs.push(blogElement)
.then((data) => {
let key = data.key
refBlogs(blogElement).update({
'id': key
})
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question