js出生年月判断是否满多少岁
async mounted() {
if (this.$route.query.type == 2) {
// this.cert为 1990-11-11
this.sex = await this.getAge(this.cert)
console.log('年龄', this.sex)
if (this.sex >= 7) {
this.sexState = false
console.log('1');
} else {
this.sexState = true
console.log('2');
}
}
this.getDetail()
},
methods: {
getAge(birthday) {
//出生时间 毫秒
var birthDayTime = new Date(birthday).getTime()
//当前时间 毫秒
var nowTime = new Date().getTime()
//一年毫秒数(365 * 86400000 = 31536000000)
return Math.ceil((nowTime - birthDayTime) / 31536000000)
},
},