发表于: 2020-05-21 23:17:33

0 2163


今天完成的事情:

学会了怎么制作日历,

主要是通过new date(),然后需要判断是否是闰年,如果能被400整除或者不能被100整除而能被4整除的是闰年,其他的都是平年。然后通过getDay()来获取每月第一天是周几。在之后的就比较好办了,通过一些其他的逻辑完成日历:

<template>
  <ul class="ds-flex flex-direction-row flex-wrap width-p100">
    <li v-for="items,index in week" class="weekLi ds-flex justify-content-center align-items-center">{{items}}</li>
    <li class="dateBtn" v-for="items,index in firstDay">{{items}}</li>
  </ul>
</template>

<script>
export default {
  name: 'calendarDate',
  data() {
    return {
      week: ['Sun','Mon','Tue','Web','Thu','Fri','Sat'],
      mouthNormel: ['31','28','31','30','31','30','31','31','30','31','30','31'],
      mouthLeap: ['31','29','31','30','31','30','31','31','30','31','30','31'],
      currentDate: '',
      currentYear: '',
      currentMouth: '',
      firstDay: '',
      moreDay: '',
    }
  },
  created() {
    let myDate = new Date()
    this.currentDate = myDate.getDate()
    this.currentYear = myDate.getFullYear()
    this.currentMouth = myDate.getMonth() + 1
    //获取某年某月第一天是周几
    let theDay = this.currentMouth  + '/' + 1 + '/' + this.currentYear
    this.firstDay = new Date(theDay).getDay()
    console.log(this.firstDay)
    if(this.currentYear%400 == 0 || (!(this.currentYear%100 == 0&& this.currentYear%4 == 0)) {
      //是闰年
      this.moreDay = 42 - this.mouthLeap[this.currentMouth - 1- this.firstDay
    }else {
      //是平年
      this.moreDay = 42 - this.mouthNormel[this.currentMouth - 1- this.firstDay
    }
  },

}
</script>

因为时间关系还没有完成,明天早上应该就可以完成日历。

明天要做的事情:

1.完成日历。

2.再自查一遍bug,然后6-10就全部完成了,交个师兄再审核一遍


返回列表 返回列表
评论

    分享到