我正在使用firestore,我想在查询中使用用户的uid
,如下所示:
methods: {
//...
},
firestore: {
Cards: db.collection("Users").doc(firebase.getCurrentUser().uid).collection("Cards")
},
async beforeMount() {
//...
}
这行不通。我得到这个错误:
Uncaught (in promise) FirebaseError: Missing or sufficientpermissions .
我尝试只是传递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"))
},
},
},