vue 基于element的日历面板 比较实用简单的希望可以帮的大家

本文介绍如何在Vue项目中使用ElementUI库创建一个实用的日历组件。通过CSS进行样式调整,使得日历面板更加符合需求。提供了一张展示效果的图片。
<div>
            <i class="el-icon-arrow-left weekStr-icon" @click="yearClick(0)"></i>
            <samp>{{dateYear}}</samp>
            <i class="el-icon-arrow-right weekStr-icon" @click="yearClick(1)"></i>
          </div>
          <div>
            <i
              class="el-icon-arrow-left weekStr-icon"
              :style="dateMonth == 1 && 'color:#ddd' "
              @click="monthClick(0)"
            ></i>
            <samp>{{dateMonth}}月</samp>
            <i
              class="el-icon-arrow-right weekStr-icon"
              :style="dateMonth == 12 && 'color:#ddd' "
              @click="monthClick(1)"
            ></i>
          </div>
        </div>
      </div>
      <el-calendar
        :scoped-slot="calendarDate"
        class="calendar-sty"
        style="height:320px"
        v-model="calendarDate"
      ></el-calendar>

在这里插入图片描述

.calendar-sty{
  .el-calendar__header{
    display: none;
  }
  .el-calendar-table .el-calendar-day{
    height: 40px;
  }
}

先用css把这块隐藏
在这里插入图片描述

date: new Date(),
calendarDate: '',
dateYear: '',
dateMonth: 0,
dateday: 0,
whetherClick: false,

  watch: {
    'dateYear' () {
      this.calendarDate = this.dateYear + '/' + this.dateMonth + '/' + this.dateday
    },
    'dateMonth' () {
      this.calendarDate = this.dateYear + '/' + this.dateMonth + '/' + this.dateday
    },
    'calendarDate' () {
      // console.log('单元格点击')
      // console.log(typeof (this.calendarDate))
      if (typeof (this.calendarDate) !== 'string') {
        this.whetherClick = true
        this.dateYear = this.calendarDate.getFullYear()
        this.dateMonth = (this.calendarDate.getMonth() + 1)
        this.dateday = this.calendarDate.getDate()
        this.whetherClick = false
      }
    }
  },
    /** 年份选择 */
    yearClick (res) {
      if (res === 1) {
        this.dateYear = this.dateYear + 1
        this.dateday = 1
      } else {
        this.dateYear = this.dateYear - 1
        this.dateday = 1
      }
    },
    /** 月份选择 */
    monthClick (res) {
      if (res === 1 && this.dateMonth !== 12) {
        this.dateMonth = this.dateMonth + 1
        this.dateday = 1
      } else if (this.dateMonth !== 1) {
        this.dateMonth = this.dateMonth - 1
        this.dateday = 1
      }
    },



效果图
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值