簡體   English   中英

如何訪問 asyncData 中的 Firestore?

[英]How can I access the firestore in asyncData?

當 asyncData 中的值為 null 時,如何以 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});
    }
  }

來自 nuxt 頻道的 Eggsy 回答:

您無權在 asyncData 中訪問它,因為它是在頁面加載之前呈現的。 但是您可以訪問 Nuxt 上下文,其中包括插件、路由器等。您可以簡單地使用參數訪問上下文或選擇您想要的內容:

async asyncData(context) {
   // Access the fire store object
   context.$fireStore;
}

// or get it from the object
async asyncData({ $fireStore }) {
   $fireStore;
} 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM