FullCalendar的日历设置

本文详细介绍了如何在Vue项目中从Vue2版本升级到Vue3,以及如何配置FullCalendar插件,包括引入、组件化、事件处理和数据绑定等。
摘要由CSDN通过智能技术生成

vue2

npm install --save @fullcalendar/vue @fullcalendar/core

vue3

npm install --save @fullcalendar/vue3 @fullcalendar/core

<script>
import '@fullcalendar/core/vdom' // solves problem with Vite
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import interactionPlugin from '@fullcalendar/interaction'
 
export default {
  components: {
    FullCalendar // make the <FullCalendar> tag available
  },
  data() {
    return {
      calendarOptions: {
        eventColor: this.getEventColor, // 使用方法来确定颜色
        firstDay: 1,
        allDaySlot: false, // 不显示all-day
        firstHour: 6,
        slotMinTime: "06:00:00",
        slotMaxTime: "24:00:00",
        plugins: [
          dayGridPlugin,
          timeGridPlugin,
          interactionPlugin // needed for dateClick
        ],
        datesSet: this.handleDatesSet,
        headerToolbar: {
          left: "prev,next today",
          center: "title",
          right: "dayGridMonth,timeGridWeek,timeGridDay"
        },

        /* 设置按钮文字 */
        buttonText: {
          today: "今天",
          dayGridMonth: "月",
          timeGridWeek: "周",
          timeGridDay: "日"
        },
        locale: "zh-cn",
        initialView: "timeGridWeek",
        // initialEvents: INITIAL_EVENTS, // alternatively, use the `events` setting to fetch from a feed
        editable: true,
        selectable: true,
        selectMirror: true,
        dayMaxEvents: true,
        weekends: true,
        // handleViewRender,
        eventDidMount: function (info) {  处理事件可以用
          if (info.event.extendedProps.isShowbgcColor) { //设置背景色
            info.el.style.background = "darkgray"
          }else{
            info.el.style.background = "#3788d8"
          }
          
        }, //事件挂载
        events: [  // 接收后端数据
           {
              title:"标题",
              start:"开始时间",
              end:"结束时间",
              color:"颜色局部",
              isShowBgcColor:"根据时间判断得出结果,在到eventDidMount里面去执行相关的方法"
            }
           


        ],
        customButtons: {
          next: {
            click: this.nextClick
          },
          prev: {
            click: this.prevClick
          },
        },
        eventColor: function (event) {
          if (event.start.isBefore(new Date())) {
            return "#f0f0f0"; // 过去事件的背景颜色
          } else {
            return "#008000"; // 未来事件的背景颜色
          }
        },

        // select: this.handleDateSelect,
        eventClick: this.handleEventClick,
        eventsSet: this.handleEvents
        /* you can update a remote database when these fire:
        eventAdd:
        eventChange:
        eventRemove:
        */
      },
    }
  }
}
</script>
<template>
  <FullCalendar :options="calendarOptions" />
</template>```

[FullCalendar官网地址](https://fullcalendar.io/docs/vue)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值