export default {
data() {
return(){
birthday:’’,//获取出生日期
form{
idc:‘440983199003214545’//身份证号
}
}
},methods: {
queryage() {//得到年龄
this.brthday=this.form.idc.substring(6,10)+"-"+this.form.idc.substring(10,12)+"-"+this.form.idc.substring(12,14);
let age=this.getAge();
console.log(“年龄为”+age);
}
// 判断用户的年龄
getAge(){
let birthdays = new Date(this.birthday.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);
return age;
},
}
}

Logo

前往低代码交流专区

更多推荐