【问题标题】:How can I access the firestore in asyncData?如何访问 asyncData 中的 firestore?
【发布时间】:2020-10-05 11:50:32
【问题描述】:

当 asyncData 中的值为 null 时,我如何以经过身份验证的用户身份访问 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});
    }
  }

【问题讨论】:

    标签: javascript firebase google-cloud-firestore nuxt.js


    【解决方案1】:

    nuxt 频道的 Eggsy 回答:

    您无权在 asyncData 中访问它,因为它是在页面加载之前呈现的。但是您可以访问 Nuxt 上下文,其中包括插件、路由器等。您可以简单地使用参数访问上下文或选择您想要的内容:

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

    【讨论】:

      猜你喜欢
      • 2021-07-17
      • 1970-01-01
      • 2019-03-21
      • 1970-01-01
      • 2020-09-12
      • 2023-03-21
      • 2020-08-17
      • 2019-02-13
      • 1970-01-01
      相关资源
      最近更新 更多