![](/img/trans.png)
[英]Flutter - Firebase Auth UID registers as Null in Firestore
[英]Use Firebase uid in firestore (Vue)
我正在使用 firestore,我想在查詢中使用用戶的uid
,如下所示:
methods: {
//...
},
firestore: {
Cards: db.collection("Users").doc(firebase.getCurrentUser().uid).collection("Cards")
},
async beforeMount() {
//...
}
這是行不通的。 我收到此錯誤:
未捕獲(承諾)FirebaseError:缺少或權限不足。
我嘗試將 uid 作為變量傳遞並在beforeMount()
中獲取它,但出現此錯誤:
無法讀取未定義的屬性(讀取“uid”)
我應該怎么辦?
問題在於 vuefire 綁定:
https://vuefire.vuejs.org/vuefire/binding-subscriptions.html#programmatic-binding
如果您需要在應用程序運行時更改綁定引用,例如顯示不同的用戶配置文件或不同的產品詳細信息頁面,聲明式綁定是不夠的。
我不得不使用程序化綁定,如下所示:
const Cards = db.collection('Users')
...
watch: {
uid: {
// call it upon creation too
immediate: true,
handler(uid) {
this.$bind('Cards', Cards.doc(uid).collection("Cards"))
},
},
},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.