vue2中使用FullCalendar注意事项以及配置项

<template>
<div class="fullCalendarStyle">
  <FullCalendar :options="calendarOptions" ref="fullCalendar"/>
  </div>
</template>

<script>
import '@fullcalendar/core/vdom' // solves problem with Vite
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import timeGridPlugin from '@fullcalendar/timegrid'
import interactionPlugin from '@fullcalendar/interaction'

  export default {
    components: {
    FullCalendar // make the <FullCalendar> tag available
  },
    data () {
      return {
         calendarOptions: {
          plugins: [ dayGridPlugin, timeGridPlugin, interactionPlugin ], // 需要使用的插件在这里注册了才能用 interactionPlugin为日历互动事件比如点击某一天
          initialView: 'dayGridMonth',
          weekends: false,
          locale: 'zh-cn', // 语言
          height: '100%',
          editable: false, // 是否可以拖
           dayMaxEvents: true, // 事件过多时隐藏
          buttonText: {month: '月', week: '周', day: '日', today: '今天'},  // 自定义按钮文字
          customButtons: {   //给按钮添加事件
            prev: {
              text: "PREV",
              click: this.changeReduce,
          },next: { // this overrides the next button
              text: "NEXT",
              click: this.changeAdd,
          },today: { // this overrides the next button
              text: "今天",
              click: this.changeToday,
          }},
          headerToolbar: {
            left: 'prev,next today',
            center: 'title',
            right: 'dayGridMonth,timeGridWeek,timeGridDay'
          },
          events: [{						// 展示数据
				    "title": "开会",
				    "date": "2021-07-01"
		    	},
			    {
			    	"title": "上班",
				"start": "2021-07-09T06:00:00+00:00"
			},
			{
				"title": "吃饭",
				"start": "2021-07-09T12:00:00+00:00"
			},
			{
				"url": "https://www.baidu.com/",
				"title": "跳转百度",
				"start": "2021-07-02",
				"end": "2021-07-07",
				"color": 'pink'
			}
		]
        }
      }
    },
    methods: {
          changeReduce () {
           let calendarApi = this.$refs.fullCalendar.getApi();
                calendarApi.prev();
                let test = calendarApi.getCurrentData().viewTitle;
                console.log(test);
          },
          changeAdd() {
            let calendarApi = this.$refs.fullCalendar.getApi();
                calendarApi.next();
                let test = calendarApi.getCurrentData().viewTitle;
                console.log(test);
          },
          changeToday() {
            let calendarApi = this.$refs.fullCalendar.getApi();
                calendarApi.today();
                let test = calendarApi.getCurrentData().viewTitle;
                console.log(test);
          }
    }
  }
</script>

<style scoped>
.fullCalendarStyle{
  padding: 20px;
  box-sizing: border-box;
  background: #fff;
  width: 100%;
  height: 93.5vh;
}
</style>

官网的npm下载容易保存,就用cnpm下载

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值