0
点赞
收藏
分享

微信扫一扫

Date前端日期变为年龄处理方法


现在页面展示效果为:

Date前端日期变为年龄处理方法_数据

 1,首先编写一个过滤器用来处理想要处理的数据

Date前端日期变为年龄处理方法_开发语言_02

 2,将要处理的数据绑定到过滤器上

Date前端日期变为年龄处理方法_数据绑定_03

3,过滤器中:输入该代码即可完成效果(重点)

 filters: {
showAge(value) {
// 指定日期
let birthdays = new Date(value.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
}
},

 4,效果

Date前端日期变为年龄处理方法_数据绑定_04

 

举报

相关推荐

0 条评论