element-ui日历组件el-calendar选中特定时间以及样式修改

项目开发中,有需要用到日历的组件,而且需要把某些日期标注起来,在这边标注的小红点我用了

el-badge

具体效果如下图所示:

 页面标签:

<div class="data-analysis">
    <el-calendar v-model="calendarValue1">
       <!--选中小红点-->
          <template
             slot="dateCell"
             slot-scope="{date, data}"
          >
             <div>
               <div v-for="(item, key) in activeday" :key="key">
                  <el-badge v-if="data.day == item.dat" is-dot class="item"></el-badge>
               </div>
               <div class="spandate">{{ data.day.split('-').slice(2).join('-') }}</div>
              </div>
           </template>
    </el-calendar>
</div>

变量声明:

// 日历
calendarValue1: new Date(),
activeday: [ // 日历组件选中的日期,小红点,时间格式必须为yyyy-MM-dd,比如3月5号要写成03-05而不是3-5
   { dat: '2023-03-21' },
   { dat: '2023-03-15' },
   { dat: '2023-03-05' }
],

样式修改:

<style lang='scss' scoped>
/*日历样式修改*/
.data-analysis /deep/  .el-calendar-table .el-calendar-day{
  width: 100%;
  height: 100%;
}
/*隐藏今天按钮*/
>>>.el-button-group>.el-button:not(:first-child):not(:last-child){
  display: none;
}
/*去掉原本背景颜色*/
.data-analysis >>>.el-calendar{
  background: transparent;
}
>>>.el-calendar-table td:hover{
  background: transparent;
}
/*去掉选中背景颜色*/
.data-analysis >>>.el-calendar-table td.is-selected{
  background: transparent;
}
/*修改每一小格大小*/
.data-analysis >>>.el-calendar-table .el-calendar-day{
  position: relative;
  padding: 10px;
}
/*小红点样式*/
.data-analysis >>>.el-badge{
  position: absolute;
  right: 5px;
  top: 5px;
}
/*日历边框颜色*/
.data-analysis >>>.el-calendar-table tr td:first-child{
  border-left: 1px solid #666666;
}
.data-analysis >>>.el-calendar-table tr:first-child td{
  border-top: 1px solid #666666;
}
.data-analysis >>>.el-calendar-table td{
  border-bottom: 1px solid #666666;
  border-right: 1px solid #666666;
}
/*表格周一到周日颜色*/
.data-analysis >>>.el-calendar-table thead th{
  color: #68a8d0;
}
/*头部日期颜色*/
.data-analysis >>>.el-calendar__title{
  color: #68a8d0;
}
/*头部下面的横线*/
.data-analysis >>>.el-calendar__header{
  border-bottom: 1px solid #666666;
}
/*鼠标悬停样式*/
.data-analysis >>>.el-calendar-table .el-calendar-day:hover{
  cursor: default;
  background: transparent;
}
/*非本月字体颜色*/
.data-analysis >>>.el-calendar-table:not(.is-range) td.next, .el-calendar-table:not(.is-range) td.prev{
  color: #666666;
  cursor: pointer;
}
</style>

参考地址

  • 4
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值