首页 > 解决方案 > vuexfire + firestore:如何存储/获取当前页面 DocumentId?

问题描述

我的用户可以生成存储在postsfirestore 集合中的帖子。当打开单个帖子页面时,我正在使用vuexfirein 操作绑定当前的帖子文档数据:

bindPostsRef: firestoreAction(context => {
    return context.bindFirestoreRef('post', db.collection("posts").where("postID", "==", postID))
})

由于每个postID都是唯一的,它总是返回一个可以访问数据的文档this.$store.state.post[0]

然后我创建了一个deletePost()操作,以便用户可以删除当前帖子页面后面的文档(如果他们是作者):

deletePost: firestoreAction((context, docID) => {
    db.collection('posts')
        .doc(docID)
        .delete()
})

我想知道检索帖子页面的当前 DocumentId 的最佳方法是什么。我想过在文档数据中添加 DocumentId 本身,这样我就可以做到$store.dispatch('deletePost', this.$store.state.post[0].docID)

处理这个问题的最佳方法是什么?

标签: firebasevue.jsgoogle-cloud-firestorevuexfire

解决方案


推荐阅读