vue中根据生日计算年龄

    getage() {
      var birthdays = new Date(this.birthday.replace(/-/g, "/"));
      var d = new Date();
      var age =
        d.getFullYear() -
        birthdays.getFullYear() -
        (d.getMonth() < birthdays.getMonth() ||
        (d.getMonth() == birthdays.getMonth() &&
          d.getDate() < birthdays.getDate())
          ? 1
          : 0);
      this.userAge = age;
    },
原文地址:https://www.cnblogs.com/huanhuan55/p/9920536.html