javascript - 如何告诉vuefire的firestore在 "created"钩子(Hook)之后执行?

标签 javascript firebase vue.js vuejs2 google-cloud-firestore

我正在使用vuefire对于我的新 Vue.js 项目。但是初始化有问题...

我的一个数据属性需要通过一种方法进行初始化。为此,我使用 Vue.js 的 created 钩子(Hook)。实际上我需要这个属性的值来满足我的 firestore 请求。

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

如何在运行创建的 Hook 后运行我的 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')
},

最佳答案

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

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

关于javascript - 如何告诉vuefire的firestore在 "created"钩子(Hook)之后执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52768057/

相关文章:

javascript - 无法从 backbone POST 到 express

javascript - 用于 Leaflet.js 的 Geojson 编码

javascript - 尝试使用 id 访问数据时,firebase 规则中的通配符不起作用

javascript - 使用 Lodash.remove 通过 Vuex 突变更改状态不会触发我的 Vue 组件中的响应式(Reactive)重新渲染

javascript - 监视父方法 Vuejs

javascript - Vuejs css 作用域性能

javascript - 使用pushState时如何出现 "browser back"?

ios - UNUserNotificationCenter didReceive/willPresent 未触发 ios 11

firebase - HMS华为管理服务

node.js - 为什么 vue-loader 和 webpack-4 不起作用?