vue 日历

<table border rules=none cellspacing=0 align=center frame=void>
            <tr id="f"><th>周一</th><th>周二</th><th>周三</th><th>周四</th><th>周五</th><th>周六</th><th>周日</th></tr>
            <tr v-for="(item,index) in 6" :key="index">
              <td v-for="(type,k) in result[index].arr" :key="k" :class="type.showActive ? 'active' : ''">
                <span v-if="!type.hide">{{type.num}}</span>
              </td>
            </tr>
          </table>

 result: [],
      y: new Date().getFullYear(),
      m: new Date().getMonth() + 1,
      d: new Date().getDate(),
      days: [],

prev() {
      if(this.m > 1){
        this.m -= 1;
      } else {
        this.m = 12;
        this.y -= 1;
      }
      this.pushDays(this.y, this.m);
    },
    next() {
      if(this.m<12){
        this.m += 1;
      } else {
        this.m = 1;
        this.y += 1;
      }
      this.pushDays(this.y, this.m);
    },
    getDays(Y,M) {
      let day = new Date(Y, M, 0).getDate()
      return day;
    },
    getWeek(Y,M){
      let now = new Date(Y,M-1,1)
      let week = now.getDay();
      return week;
    },
    pushDays(Y,M) {
      this.days = [];
      this.result = [];
      var yN = new Date().getFullYear();
      var mN = new Date().getMonth() + 1;
      //将这个月多少天加入数组days
      for(let i = 1; i <= this.getDays(Y,M); i++) {
        this.days.push({ num: i, hide: false, showActive: yN == Y && mN == M && i == this.d ? true : false })
      }
      //将下个月要显示的天数加入days
      for(let i = 1; i <= 43 - this.getDays(Y,M) - this.getWeek(Y,M) ; i++) {
        this.days.push({ num: i, hide: true, showActive:false })
      }
      //将上个月要显示的天数加入days
      let lastMonthDays = this.getDays(Y, M)
      for(let i = 1; i < this.getWeek(Y,M) ; i++) {
        this.days.unshift({ num: lastMonthDays - i, hide: true, showActive:false })
      }
      
      for(let i = 0; i < this.days.length; i += 7) {
        this.result.push({arr : this.days.slice(i, i + 7)})
      }
    },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值