Javascript 如何告诉vuefire';s firestore将在“之后执行”;“创建”;钩

Javascript 如何告诉vuefire';s firestore将在“之后执行”;“创建”;钩,javascript,firebase,vue.js,vuejs2,google-cloud-firestore,Javascript,Firebase,Vue.js,Vuejs2,Google Cloud Firestore,我正在为我的新Vue.js项目使用。但是初始化有一个问题 我的一个数据属性需要通过一个方法初始化。为此,我使用创建的Vue.js钩子。实际上,我需要firestore请求的这个属性的值 问题是:firestore请求似乎在创建的钩子之前运行 在创建的钩子运行后,如何运行firestore请求 谢谢! data: function () { return { currentWeek: null } }, firestore: function (currentWeek) { r

我正在为我的新Vue.js项目使用。但是初始化有一个问题

我的一个数据属性需要通过一个方法初始化。为此,我使用创建的Vue.js钩子。实际上,我需要firestore请求的这个属性的值

问题是:firestore请求似乎在创建的钩子之前运行

在创建的钩子运行后,如何运行firestore请求

谢谢!

data: function () {
  return {
    currentWeek: null
  }
},
firestore: function (currentWeek) {
  return {
    slots: db.collection('slots').where('start', '>=', this.currentWeek)
  }
},
created: function () {
  this.currentWeek = moment().startOf('week')
},

这不是确切的代码,但基本上您希望使用
$firestoreRefs
创建的
生命周期方法中自己进行查询

data: function () {
  return {
    currentWeek: null,
    slots : []
  }
},
created: function () {
  this.currentWeek = moment().startOf('week')
  this.slots = this.$firestoreRefs['slots'].where('start', '>=', this.currentWeek)
},

我发现我可以用手表和装订解决这个问题:

data: function () {
  return {
    currentWeek: null,
    slots: []
  }
},
created: function () {
  this.currentWeek = moment().startOf('week')
},
watch: {
  currentWeek (currentWeek) {
    this.$bind('slots', db.collection('slots')
      .where('start', '>=', moment(currentWeek).toDate())
  }
}

我很确定可以找到更好的解决方案…

好吧,这个解决方案似乎不是这样的。$firestoreRefs.where不直接返回结果。。。此外,如果firestore配置中未定义插槽,$firestoreRefs['slots']不存在如果您想要更完整的答案,则需要提供更多代码,如果没有项目,我只能做出假设。。。我说过,这是完整的解决方案,但旨在为您指明使用REF的方向,这些REF被定义为精确地进行初始查询,很抱歉没有提供足够的代码,非常感谢您的回答。我提出了一个似乎有效的解决方案,但我确信您的解决方案更优雅。我只需要找到如何得到结果,因为.where()不返回承诺。。。