vue中根据生日(出生年月日)计算年龄
<template><div class="role" :style="backgroundImg"></div></template><script>export default{data(){return {teacherBirthday:'',...
·
<template>
<div class="role" :style="backgroundImg">
</div>
</template>
<script>
export default{
data(){
return {
teacherBirthday:'',//出生年月日
teacherAge:'',//年龄
}
},
methods:{
// 判断用户的年龄
getAge(){
let birthdays = new Date(this.teacherBirthday.replace(/-/g, "/"));
let d = new Date();
let age =
d.getFullYear() -
birthdays.getFullYear() -
(d.getMonth() < birthdays.getMonth() ||
(d.getMonth() == birthdays.getMonth() &&
d.getDate() < birthdays.getDate())
? 1
: 0);
this.teacherAge = age;
},
}
}
</script>
更多推荐
已为社区贡献7条内容
所有评论(0)