Fork me on GitHub

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;
    },

 

posted @ 2018-11-07 09:05  欢欢11  阅读(4819)  评论(0编辑  收藏  举报