Using Nxt.js and firebase, we are creating a program to calculate the age based on the date of birth as information for dojo students.The calculation went well, but I'm in trouble because I can't display the calculation results well.
Cannot read property 'age' of undefined
<template>
approximately
<td>{{this.age}} years old</td>
approximately
</template>
export default {
data(){
US>return{
age:',
},
created(){
This.$store.dispatch('setStudentsRef', db.collection('students'));
// Calculate Age //
const studentRef=db.collection('students');
studentRef.get().then(querySnapshot=>{
querySnapshot.forEach(birthDayDocSnapshot=>{
const birthdayDay=birthDayDocSnapshot.data().pickerDate;
const today = moment();
letty=Math.floor(moment.duration(today.diff(birthday))).as('months')/12);
This.age=y;
});
});
},
Considering console.log(this.age), the numerical data is properly captured.
It doesn't seem like a callback function problem, and I'm at a loss what to do.
The same questions are posted here.
https://teratail.com/questions/301462?modal=q-comp
It's solved.This.age is now displayed as age.
© 2024 OneMinuteCode. All rights reserved.