Vue中使用Fullcalendar日歷開發(fā)日程安排

一、效果圖

image.png

官網(wǎng)地址:Vue Component - Docs | FullCalendar

二、安裝使用

1、使用 npm install 安裝下列依賴
image.png
2、在需要使用的頁面中引入
<FullCalendar ref="fullCalendar" :options="calendarOptions"></FullCalendar>
3、在頁面中引入需要的插件
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import timeGridPlugin from '@fullcalendar/timegrid'
import interactionPlugin from '@fullcalendar/interaction'
4、在data中設(shè)置日歷的一些配置及屬性
data(){
  return{
     calendarOptions:{
        plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
        initialView: 'dayGridMonth',
        locale: 'zh',
        firstDay: 1,
        buttonText: {
          today: "今天",
          month: "月",
          week: "周",
          day: "日",
          // list: "列表",
        },
        headerToolbar: {
          left: 'prev,next today',
          center: 'title',
          right: 'dayGridMonth,timeGridWeek,timeGridDay',
        },
        weekNumberCalculation: 'ISO',
        nowIndicator: true,
        height:500,
        validRange: this.validRange,  //設(shè)置可顯示的總?cè)掌诜秶?        eventTimeFormat: { // 在每個事件上顯示的時間的格式
          hour: 'numeric', // numeric:2022,2-digit:22
          minute: '2-digit',
          meridiem: false,
          hour12: false // 設(shè)置時間為24小時
        },
        customButtons: {
          next: {
            click: this.nextClick
          },
          prev: {
            click: this.prevClick
          }
        },
        editable: false, //允許拖動縮放,不寫默認就是false
        overlap: false, //允許時間重疊,即可以與其他事件并存,不寫默認就是false
        events: [], //背景色 (添加相同時間的背景色時顏色會重疊)
        datesSet: this.datesSet, //日期渲染;修改日期范圍后觸發(fā)
        eventClick: this.handleEventClick, //點擊日程觸發(fā)
        dateClick: this.handleDateClick, //點擊日期觸發(fā)
        eventDrop: this.calendarEventDropOrResize, //拖動事件觸發(fā)
        eventResize: this.calendarEventDropOrResize, //縮放事件觸發(fā)
        displayEventTime: false, //不顯示具體時間
      }
  }
}
5、在methods中添加點擊上一月、下一月和今天的事件
method:{
    nextClick() {
      this.$refs.fullCalendar.getApi().next() // 將日歷向前移動一步(例如,一個月或一周)。
    },
    prevClick() {
      this.$refs.fullCalendar.getApi().prev() // 將日歷后退一步(例如,一個月或一周)。
    }
}
6、在頁面初始化數(shù)據(jù)完成后進行數(shù)據(jù)整合 讓數(shù)據(jù)符合要求
  形如:
  obj={ id,title,start,end}
  this.calendarOptions.events.push(obj);

三、至此日歷模型已完成 后續(xù)有其他的修改可在此基礎(chǔ)上微調(diào)。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容