简体   繁体   English

为什么使用 Vue.js 时,来自 Firebase 实时数据库的数据仅在控制台中呈现,而不在页面上呈现?

[英]Why is data from the Firebase realtime database only rendering in the console, but not on the page while using Vue.js?

When I try to render a value stored in my Firebase Realtime Database, I can see it when I console.log, but it won't render on the page while using the {{ exams.name }} syntax in Vue.当我尝试渲染存储在我的 Firebase 实时数据库中的值时,我可以在 console.log 中看到它,但在 Vue 中使用 {{ Exams.name }} 语法时它不会在页面上渲染。 When I setup the same thing, but using Firestore, I was able to render it onto the page.当我设置相同的东西但使用 Firestore 时,我能够将它呈现到页面上。

I am using this code in my main dashboard view:我在我的主仪表板视图中使用此代码:

import firebase from '@/firebase/firebaseConfig.js'
import db from '@/firebase/firebaseConfig.js'
import { database } from '@/firebase/firebaseConfig.js'

export default  {

  data() {
    return {
      checkpointReward: {},
      subscribersGained: {},
      ordersRecevied: {},
      salesBarSession: {},
      supportTracker: {},
      productsOrder: {},
      salesRadar: {},
      totalStudents: {},
      examRef: {},
      exams: {},
      studentName: {},
      students: {},
      testingData: {},
      analyticsData,
      dispatchedOrders: []
  }
},

   // Initialize Firebase
    const examRef = database.ref('exams');
        
      examRef.on('value', gotData, errData);

        function gotData(data) {
          const exams = data.val();
          const studentData = exams.name;
          console.log(exams.name);
        }

        function errData(err) {
          console.lof("Error!");
          console.log(err);
        }

I don't know if you pasted your code without some part of the component, but this part should be inside a method and assign the value to this.desired_state_value like so:我不知道您是否在没有组件的某些部分的情况下粘贴了代码,但这部分应该在方法内并将值分配给 this.desired_state_value ,如下所示:

  export default  {

      data() {
        return {
         checkpointReward: {},
         subscribersGained: {},
         ordersRecevied: {},
         salesBarSession: {},
         supportTracker: {},
         productsOrder: {},
         salesRadar: {},
         totalStudents: {},
         examRef: {},


        [...]
     },
  methods: {
     getExams(){
        // Initialize Firebase
        this.examRef = database.ref('exams');
    
        this.examRef.on('value', gotData, errData);

        function gotData(data) {
           const exams = data.val();
           const studentData = exams.name;
           console.log(exams.name);
    }

      function errData(err) {
         console.lof("Error!");
         console.log(err);
    }
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Vue.js 从 Firebase 实时数据库读取数据 - How to read data from Firebase Realtime Database with Vue.js 无法将 Firebase 实时数据库中的数据保存到 Vue.js 中的数组,并将其用于在 Vue2-google-maps 上显示标记 - Cannot save data from Firebase realtime database to array in Vue.js, and use it for displaying markers on Vue2-google-maps 使用 Vue 3 + Firebase 实时数据库读取数据 - read data using Vue 3 + Firebase realtime database Vue.js - 延迟页面渲染,直到数据请求完成 - Vue.js - defer page rendering until data request finishes 使用Firebase实时数据库和VueFire的Vue.js应用程序突然停止工作 - Vue.js app with Firebase realtime database and VueFire suddenly stopped working 如何在 vue.js 中从 api 渲染数据 - how to rendering data from api in vue.js TypeError:无法使用 Vue.js 中的实时 Firebase 设置未定义返回的 JSON 问题的属性 - TypeError: Cannot set property of undefined returned JSON issue using Realtime Firebase in Vue.js 如何仅使用vue从外部文件将数据加载到vue.js - How to load data into vue.js from an external file using vue only 渲染 vue.js 组件并传入数据 - rendering vue.js components and passing in data 为什么页面刷新时firebase的实时数据库不加载数据 - Why is firebase's Realtime Database not loading data when page refreshes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM