我正在使用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')
},
最佳答案
这不是确切的代码,但基本上您希望使用 $firestoreRefs
在 created
生命周期方法中自行进行查询
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/