vue 通过身份证号码判断用户年龄
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;
},
}
}
總結
以上是生活随笔為你收集整理的vue 通过身份证号码判断用户年龄的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 「硬见小百科」很全的CPU处理器技术架构
- 下一篇: excel之非常实用的模糊查询