firebase - vuexfire + firestore:如何存储/获取当前页面 DocumentId?
问题描述
我的用户可以生成存储在posts
firestore 集合中的帖子。当打开单个帖子页面时,我正在使用vuexfire
in 操作绑定当前的帖子文档数据:
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)
。
处理这个问题的最佳方法是什么?
解决方案
推荐阅读
- ruby-on-rails - Rails ActiveStorage 处理后更新附件
- sql - 您如何使用 postgreSQL 将多个结果分组到一个列中并为每个结果计数
- html - Angular组件应用父指定样式
- elasticsearch - Search Guard 未初始化 (SG11)
- r - 如何使用 R 中的 MICE 包估算丢失的数据?
- javascript - 在 ChartJS 中重新创建此图
- javascript - 如何通过回调为变量赋值?
- python - 有没有办法从外部对字典进行排序
- android - 在创建移动应用程序时,我们如何摆脱 android 和 ios 环境?
- mysql - 向 mysql gcp 实例添加私有 IP 时出现问题