Les comparto mi solución al problema de calcular la edad en base a la fecha de nacimiento.
<template>
<div id="app">
<input v-model="name" type="text">
<input v-model="lastName" type="text">
<input v-model="fechaNac" type="date">
<h4>{{edad}}</h4>
</div>
</template>
<script>
export default {
data(){
return{
name:"",
lastName:"",
fechaNac:""
}
},
computed:{
edad() {
let now = new Date().getFullYear();
let anios= now - this.fechaNac.slice(0,4);
return `${this.name} ${this.lastName} tiene ${anios} años`
}
}
}
</script>
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?
o inicia sesión.