欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 金融 > 【vue】【element-plus】 el-date-picker使用cell-class-name进行标记,type=year不生效解决方法

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

2025/4/28 3:56:01 来源:https://blog.csdn.net/Anlittlecat/article/details/147509273  浏览:    关键词:【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无效问题

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词