I created a program in Nxt.js to play age from date of birth, but it doesn't show up.

Asked 2 years ago, Updated 2 years ago, 92 views

Prerequisites/What you want to achieve

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.

Problems/Error Messages you are experiencing

Cannot read property 'age' of undefined

Source Codes Affected

<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;
      });
    });
  },

Tried

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.

Supplementary information (for example, FW/Tool Version)

The same questions are posted here.
https://teratail.com/questions/301462?modal=q-comp

firebase nuxt.js

2022-09-29 21:50

1 Answers

It's solved.This.age is now displayed as age.


2022-09-29 21:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.