在asyncData中为空时,如何在asyncData中以经过身份验证的用户身份访问firestore?
async asyncData(){
console.log(this);
try{
const data = await this.$fireStore
.collection("users")
.doc("dgsxhchdxfwsezgxrd")
.collection("games").doc("test")
.collection("verions").doc("v0.0.1").get();
console.log(firestore success ${data});
return{ gameData: data};
}catch(error){
console.log(firestore error ${error});
}
}发布于 2020-10-05 19:50:33
来自nuxt频道的Eggsy回答道:
您不能在asyncData中访问它,因为它是在页面加载之前呈现的。但您可以访问Nuxt上下文,其中包括插件、路由器等。您可以简单地使用参数访问上下文,或者选择您想要的内容:
async asyncData(context) {
// Access the fire store object
context.$fireStore;
}
// or get it from the object
async asyncData({ $fireStore }) {
$fireStore;
} https://stackoverflow.com/questions/64208059
复制相似问题