vuejs获取一周的时间(就是前七天)


data: () => ({
    msg: "Welcome to Your Vue.js App",
    week: []
}),
created() {
    let data = [];
    for (let i = 6; i >= 0; i--) {
      data.push(this.getWeek(-i));
    }
    this.week = data;
    console.log(this.week);
},
methods: {
   getWeek(day) {
     var today = new Date();
     var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
     today.setTime(targetday_milliseconds);
     var tYear = today.getFullYear();
     var tMonth = today.getMonth();
     var tDate = today.getDate();
     tMonth = this.doHandleMonth(tMonth + 1);
     tDate = this.doHandleMonth(tDate);
     return tYear + "-" + tMonth + "-" + tDate;
   },
   doHandleMonth(month) {
     var m = month;
     if (month.toString().length == 1) {
       m = "0" + month;
     }
     return m;
   }
}
以上是编程学习网小编为您介绍的“vuejs获取一周的时间(就是前七天)”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。

本文标题为:vuejs获取一周的时间(就是前七天)

基础教程推荐