我正在使用vuexfire将firebase引用绑定到我的app状态。
这很好用:
bindRef: firebaseAction(({bindFirebaseRef}, payload) => {
let firebaseRef = db.collection(`/${payload}`)
bindFirebaseRef('storeProperty',firebaseRef)
})
然而,我只想在成功获得之后进行绑定;这样我就能捕捉错误并设置进度指示。
这样的事情:
bindRef: firebaseAction(({bindFirebaseRef}, payload) => {
let firebaseRef = db.collection(`/${payload}`).get().then(e => {
//where ref is same as firebaseRef
bindFirebaseRef('questions',ref)
})
})
答案 0 :(得分:1)
您需要将对该集合的引用声明为变量,然后才能将其传递给您的函数:
bindRef: firebaseAction(({bindFirebaseRef}, payload) => {
let firebaseRef = db.collection(`/${payload}`)
firebaseRef.get().then(e => {
//pass firebaseRef to the function
bindFirebaseRef('questions',firebaseRef)
})
})