fullcalendar日历插件的基本使用(vue)

一、官网地址及中文文档

官网地址: Demos | FullCalendar 
中文文档:FullCalendar 中文说明文档 (bytenote.net)
 

二、示例demo

1、代码

注意:

events的数据格式是需要title、start、end这样的,

插槽的arg不是随便起名字的。
如果需要添加点击事件需要加这个:dateClick:handleClick  但是前提是必须引入interactionPlugin ,否则会不起作用!!!!!!!!!!!

<template>
  <div>
    <FullCalendar :options="calendarOptions" ref="fullcalendarref">
      <template #eventContent="arg">
        <div class="custom-event">
          {{ arg.event.title }}
        </div>
      </template>
    </FullCalendar>
  </div>
  <!-- 点击弹窗 -->
  <edit ref="editRef"></edit>
</template>
<script setup lang="ts">
import FullCalendar from '@fullcalendar/vue3';
import dayGridPlugin from '@fullcalendar/daygrid';
import interactionPlugin from '@fullcalendar/interaction';
import locale from '@fullcalendar/core/locales/zh-cn';

const matchList = ref<any>([]); //日历数据
const fullcalendarref = ref(); //实例
const handleClick=(val)=>{
  // console.log(val.dateStr);
  //debugger

}

//这个calendarOptions是配置项 这里只是部分配置项
const calendarOptions = ref({
  plugins: [dayGridPlugin,interactionPlugin],//插件  我目前用的是月视图插件
  initialView: 'dayGridMonth',//视图
  height: '780px',
  locale: locale, //语言汉化
  firstDay: 1, // 设置一周中显示的第一天是哪天,周日是0,周一是1,类推
  editable: true, //事件是否可编辑,可编辑是指可以移动, 改变大小等。
  droppable: true, //是否可拖拽
  headerToolbar: {
    left: '',
    center: 'title',
  },
  dateClick:handleClick, 
  //   dropAccept: ".eventListItems", //可被拖进
  initialDate: dayjs().format('YYYY-MM-DD'), // 自定义设置背景颜色时一定要初始化日期时间
  events: matchList.value, //绑定展示事件
});
const init = async () => {
  matchList.value = [];
  // const res = await getCalendarEvent({
  //   status: '', //状态
  //   bgColor: '', //背景颜色
  // });
  // let evenstList = res.map((item: any) => {
  //   item.title = item.title;
  //   item.eventId = item.id;
  //   item.start = item.start_time;
  //   item.end = item.end_time;
  //   return item;
  // });
//目前的数据是用死的  
  let evenstList = [
    {
      id: '0',
      title: '节假日',
      start: '2024-01-25',
      end: '2024-01-25',
    },
    {
      id: '1',
      title: '双休日',
      start: '2024-01-27',
      end: '2024-01-27',
    },
    {
      id: '2',
      title: '双休日',
      start: '2024-01-28',
      end: '2024-01-28',
    },
  ];

  matchList.value = [...evenstList];
  calendarOptions.value.events = matchList.value;
};
onMounted(() => {
  init();
  
});
</script>
2、效果展示
  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值