【问题标题】:VuexFire Synchronization with bind not working带有绑定的VuexFire同步不起作用
【发布时间】:2021-03-16 00:33:15
【问题描述】:

我目前正在使用 VuexFire 将 Cloud Firestore 绑定到我的 Vuex 状态。我在让它工作时遇到了一些问题,我们将不胜感激。

我目前正在做的事情如下:

Vue.js 文件:

  methods:{
    ...mapActions("comments", ['bindArticleComments']),
 },created(){
    this.bindArticleComments()
  },

动作/cmets 文件

  export const bindArticleComments = firestoreAction(({ bindFirestoreRef }) => {
    return bindFirestoreRef('articleComments', collectionRef('comments'))
  })

firebase 服务文件

export const collectionRef = (collectionName) => {
  return firestore().collection(collectionName)
}

奇怪的是,我已经在为不同的 Vuex 状态字段执行相同的过程。它似乎在没有问题的情况下工作。有没有人认为我做得不好?

【问题讨论】:

    标签: google-cloud-firestore vuex vuexfire


    【解决方案1】:

    奇怪的是,我得到了它的工作,虽然我很难理解它是如何工作的以及为什么工作。在我的 Vue js 文件中,我在下载数据和创建后放置了 this.bindArticleComments()。

    methods:{
     downloadComments(){
            const { articlesCommentRef } = this.$fb
    
            articlesCommentRef(this.loadedArticle.id).get()
              .then(querySnapshot => {
                  this.setArticleComments(querySnapshot.docs.map((doc) => doc.data()))
                  this.bindArticleComments(this.loadedArticle.id)})
              .catch(error => console.log("Error getting documents: ", error))
              .finally(() => {this.$q.loading.hide()})
          }
    },
     created(){
        this.bindArticleComments(this.loadedArticle.id)
      },
      mounted(){
            this.downloadComments()
      }
    

    【讨论】:

    • 我自己在使用 vuexfire 时遇到了一些奇怪的绑定。在您的情况下,何时加载加载文章?
    猜你喜欢
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-31
    • 2021-11-08
    • 1970-01-01
    • 2012-11-08
    • 2018-01-11
    相关资源
    最近更新 更多