React整合FullCalendar笔记(一)

React整合FullCalendar笔记(一)

前期

因为公司的需求,需要一个可以拖动的日历效果。经过前期的调研,找到 FullCalendar 框架比较符合项目的需求。但是碍于现在关于这个框架的文档都比较零散和不全。在经过几天的调研中,我大概实现了部分的功能,由此想做一系列的博文跟大家分享一下。

实现效果

第一期,我们就简单的使用这个框架,在页面上面单纯的展示在页面中。
在这里插入图片描述

主要代码

import React, { useRef, useState } from 'react'
import {Modal} from 'antd'
import FullCalendar from '@fullcalendar/react' // must go before plugins
import dayGridPlugin from '@fullcalendar/daygrid' // a plugin!
import interactionPlugin from "@fullcalendar/interaction"
import locale from '@fullcalendar/core/locales/zh-cn';
import "@fullcalendar/timegrid/main.css";

 <div style={{ width: "50vw", height: '50vh', marginLeft: "10vw" }}>
      <FullCalendar
        // interactionPlugin 移动使用插件
        // dayGridPlugin 日期网格插件
        plugins={[ dayGridPlugin, interactionPlugin ]}
        // 头部展示
        headerToolbar={{
          //  默认显示当前年月
          left: "title",
          // 设置中间显示的内容
          // center: "title",
          // 右侧上一月,下一月,今天(逗号为紧相邻,空格为有间隙,不写哪个就不展示哪个按钮)
          right: "prev,next today"
        }}
      	// 设置可以编辑:拖动,缩放
        editable={true}
        initialView="dayGridMonth"
        // 空白点击事件
        dateClick={handleDateClick}
        // 这个中文显示
        locale={locale}
        // 设置可丢弃
        droppable={true}
        // 事件数据
        events={[
          // display: 'background', 
          { title:'女神节', start: '2021-12-14', end:"2021-12-17", backgroundColor:"green", id:"1", textColor:'white'},
          { title:'女神节2', start: '2021-12-07', end:"2021-12-09", backgroundColor:"Orange", id:"1", textColor:'white'},
          { title:'女神节1', start: '2021-12-16', end:"2021-12-20", backgroundColor:"red", id:"4", textColor:'white'},
          { title:'99活动 甲乙丙',start: '2021-12-14', end:"2021-12-15", backgroundColor:"blue", id:"2", textColor:'white', display:'list-item'},
          { title:'99活动1',start: '2021-12-14', end:"2021-12-15", backgroundColor:"blue", id:"3", textColor:'white', display:'list-item'},
          { title:'99活动2',start: '2021-12-14', end:"2021-12-15", backgroundColor:"blue", id:"3", textColor:'white', display:'list-item'},
          { title:'99活动3',start: '2021-12-14', end:"2021-12-15", backgroundColor:"blue", id:"3", textColor:'white', display:'list-item'}
        ]}
      />
    </div>

本篇只是让大家初步体验体验这个组件,后续还会更多的知识点分享给大家。大家可以到 官方文档 进行学习。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值