You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React中Fullcalendar.io默认仅显示周视图的实现方法

实现FullCalendar默认仅显示系统周视图(无需自定义视图)

完全可以实现,不需要创建自定义视图,只需通过简单配置即可达成需求,具体操作步骤如下:

  • 安装必要依赖
    确保项目中已安装FullCalendar的React核心包和周视图插件:

    npm install @fullcalendar/react @fullcalendar/timegrid
    
  • 在React组件中导入模块
    引入FullCalendar核心组件和周视图插件:

    import FullCalendar from '@fullcalendar/react';
    import timeGridPlugin from '@fullcalendar/timegrid';
    
  • 配置FullCalendar组件
    通过initialView指定默认显示系统自带的周视图(timeGridWeek),同时通过headerToolbar移除其他视图的切换入口,确保用户无法切换到其他视图:

    function MyCalendar() {
      return (
        <FullCalendar
          plugins={[timeGridPlugin]}
          initialView="timeGridWeek"
          headerToolbar={{
            left: 'prev,next today',
            center: 'title',
            right: '' // 不显示其他视图切换按钮
          }}
          // 可添加其他业务相关配置,比如事件数据等
        />
      );
    }
    
    export default MyCalendar;
    

如果只是需要默认显示周视图,但保留切换其他视图的入口,只需保留headerToolbar中的视图切换按钮(比如'dayGridMonth,timeGridWeek'),同时设置initialView="timeGridWeek"即可,但根据你的需求,移除切换按钮就能确保仅显示周视图。

内容的提问来源于stack exchange,提问作者Heavenly Journey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 00:20:55