[英]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.