当前位置: 首页 > news >正文

【vue】【element-plus】 el-date-picker使用cell-class-name进行标记,type=year不生效解决方法

type=dete,自定义cell-class-name打标记效果如下:
在这里插入图片描述

相关代码:
        <el-date-pickerv-model="date":clearable="false":editable="false":cell-class-name="cellClassName"type="date"format="YYYY-MM-DD"value-format="YYYY-MM-DD"></el-date-picker>//customDateArr : ['2025-04-01', '2025-04-23','2025-04-11']cellClassName:(date)=>{let that = thislet nDate = parseTime(date, '{y}-{m}-{d}')//日期格式化方法// console.log(nDate)if (that.customDateArr.includes(nDate)) {return 'custom_date_class'; // 应用自定义样式类}return ''; // 其他日期不应用样式},
<style lang="scss">
.custom_date_class {span::after{content: "";position: absolute;width: 6px;height: 6px;background: var(--el-color-danger);border-radius: 50%;bottom: -5px;left: 50%;transform: translateX(-50%);}
}
</style>
type=year相关内容:

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

同样方法,当type=year时候,改成对应年份匹配后发现方法没有被调用,使用官方文档中的插槽方式(已升级到最新版)也无法实现。
最后通过焦点事件和面板更换事件直接操作dom元素进行强制赋值解决!!

<div class="select-center-left date-select"><el-date-pickerpopper-class="custom-year-picker"v-model="year":clearable="false":editable="false"type="year"value-format="YYYY"@focus="handleYearPickerOpen"@panel-change="handleYearPickerOpen":disabled-date="disabledDate"/>const handleYearPickerOpen = () => {nextTick(() => {const pickerPanel = document.querySelector(' .custom-year-picker');// console.log(pickerPanel)if (pickerPanel) {const cells = pickerPanel.querySelectorAll('td');cells.forEach(cell => {// 示例:为 2023 年的单元格添加样式if (cell.textContent.includes('2023')||cell.textContent.includes('2019')) {cell.classList.add('custom_date_class');}else {//不匹配需手动移除,否则切换面板后上次样式依旧存在cell.classList.remove('custom_date_class')}});}});
};

类型为月份相关解决:element-ui的日期选择器cellClassName无效问题

相关文章:

  • DeepSeek回答过于笼统,提示词如何优化
  • RK3562/3588 系列之0—NPU基础概念
  • 高防IP+CDN组合:电商大促的“双保险”防护方案
  • 常见网络安全攻击类型深度剖析(二):SQL注入攻击——原理、漏洞利用演示与代码加固方法
  • linux系统问题杂谈
  • 六个能够白嫖学习资料的网站
  • Spring MVC 数据绑定利器:深入理解 @InitBinder
  • 猿人学题库13题—动态css字体加密 记录
  • 深入理解指针 (1)
  • Unity 打包后 无阴影 阴影不显示
  • Hi3516CV608 超高清智慧视觉 SoC 芯片 可提供开发资料
  • 论分布式事务及其解决方案 架构师论文范文(考试笔记)
  • 电力系统惯性与惯量关系解析
  • SCI论文结构笔记
  • ctfshow-web-新春欢乐杯
  • 【使用层次序列构建二叉树(数据结构C)】
  • 脚本分享:快速作图对比wannier拟合能带python脚本
  • 深入理解C语言变量:从基础到实践
  • 《深入浅出ProtoBuf:从环境搭建到高效数据序列化》​
  • 三串口进行试验
  • 准“90后”山西壶关县委常委、副县长高雅亭赴北京密云挂职
  • “五一”假期云南铁路预计发送旅客超330万人次
  • 释新闻|印度宣布“掐断”巴基斯坦水源,对两国意味着什么?
  • 云南舞蹈大家跳暨2025年牟定“三月会”昨天开幕
  • “网红”谭媛去世三年:未停更的账号和困境中的家庭
  • 上海开展2025年“人民城市 文明风采”群众性主题活动