vue3+elementPlus el-calendar如何标出多个时间

先上效果图

 上代码

<template>
	<div  style="text-align: center;">
          <el-calendar style="width:600px;" v-model="nowdate">
            <template #date-cell="{data}">
                <div>
                  <p :class="[findDate(data) > -1?'activeItem':'']">{{ data.day.split('-').slice(2).join('-') }}</p>
                </div>
              </template>
          </el-calendar>
	</div>
</template>
<script setup>
  import {ref, onMounted } from "vue";
  let nowdate = ref(new Date())
  let activeday = ref([
    {dat:'2024-03-25'},
    {dat:'2024-03-26'},
    {dat:'2024-03-28'},
    {dat:'2024-03-29'}
  ])
  const findDate = (date) =>{
    let index = activeday.value.findIndex(item =>{
        return item.dat == date.day
    })
    return index
  }
</script>
<style>
  .activeItem{
    color:red;
  }
  .el-calendar-table td.is-today{
    color:#000 !important;
    background: transparent !important;
  }

</style>

注意

dateCell scoped slot 参数 : data { type, isSelected, day}

  • type 表示该日期的所属月份,可选值有 prev-month,current-month,next-month;
  • isSelected 标明该日期是否被选中;
  • day 是格式化的日期,格式为 yyyy-MM-dd

显示在日历上日期方法:

  data.day.split('-').slice(2).join('-')

 

 

相关推荐

  1. vue3时间获取

    2024-03-26 14:06:04       48 阅读
  2. Vue3 时间格式化

    2024-03-26 14:06:04       7 阅读
  3. 花一时间vue3 重制了 vue-styled-components

    2024-03-26 14:06:04       15 阅读
  4. Vue3练习】Vue3使用v-model以及v-model

    2024-03-26 14:06:04       37 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-26 14:06:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-26 14:06:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-26 14:06:04       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-26 14:06:04       20 阅读

热门阅读

  1. 设计模式概念、分类和原则

    2024-03-26 14:06:04       16 阅读
  2. ThreadLocal的主要特点:

    2024-03-26 14:06:04       19 阅读
  3. B+ 树和B树有什么区别,数据库索引为什么用B+树

    2024-03-26 14:06:04       19 阅读
  4. FastAPI+React全栈开发07 MongoDB数据库的结构

    2024-03-26 14:06:04       17 阅读
  5. [BJDCTF2020]伏羲六十四卦

    2024-03-26 14:06:04       18 阅读
  6. Pandas基础之查找和筛选数据

    2024-03-26 14:06:04       18 阅读
  7. c语言弹球小游戏

    2024-03-26 14:06:04       16 阅读