【问题标题】:Vuefire data not subscribing to changesVuefire 数据未订阅更改
【发布时间】:2021-06-09 19:53:35
【问题描述】:

我有几个不同的查询需要保留“实时”数据。当我对查询进行硬编码时,它成功显示了数据库中发生的所有实时更改。但是当我传递一个有效载荷时,数据在重新加载之前不会改变。

工作查询:

getOnline: firestoreAction(({ bindFirestoreRef }) => {
      
      return bindFirestoreRef('online', db.collection('units').where('unit.on', '==', true).orderBy('info.timestamp', 'desc').orderBy('unit.status'))

    }),

Payload Query 无效:获取数据一次

getFilterSystemId: firestoreAction(({ bindFirestoreRef} , payload) => {
      
      return bindFirestoreRef('filterBySystemId', db.collection('units').where('unit.group', '==', payload.group).orderBy('info.timestamp', 'desc').orderBy('unit.status'))

    }), 

我只是简单地传递有效载荷:

filterSystemId(grouphex){

    let payload  = {
      group: grouphex.toString(),
    }

    this.getFilterSystemId(payload);

  },

如何传递有效负载并获取数据库中发生的任何更改的实时更新?

【问题讨论】:

    标签: javascript firebase google-cloud-firestore vuejs2 vuefire


    【解决方案1】:

    最终使用 vuefire 而不是 vuexfire 并像这样动态绑定我的查询。

    const vuefire = db.collection('vuefire')
    
    export default {
      components: {},
      data() {
        return {
        //view
        vuefire: [],
        id: 'true',
        user: [],
        code: 'true'
         
        };
      },
    
      created() {
      },
    
      // firestore: {
      //   vuefire: db.collection('vuefire')
      // }
    
      watch: {
        id: {
          // call it upon creation too
          immediate: true,
          handler(id) {
            this.$bind('user', vuefire.where('a', '==', id))
          },
        },
    

    任何时候 'id' 更改数据集('user')都会重新计算并实现我的目标

    【讨论】:

      猜你喜欢
      • 2021-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-13
      • 1970-01-01
      • 2019-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多