在Vue項目中用fullcalendar制作日程表的示例代碼
前言
最近老牌日歷插件fullcalendar更新了v4版本,而且添加了Vue支持,所以用最新的fullcalendar v4制作一個完整日歷體驗一下,效果圖:

安裝
FullCalendar的功能被分解為“插件”。如果您需要它提供的功能,您只需要包含一個插件。
也就是說,F(xiàn)ullCalendar v4所有插件都得單獨安裝引用。
npm install --save @fullcalendar/vue @fullcalendar/core @fullcalendar/daygrid
引用并初始化
引用、注冊FullCalendar組件,得到一個月視圖的日歷。
<script>
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
export default {
components: {
FullCalendar
},
data() {
return {
calendarPlugins: [ dayGridPlugin ]
}
}
}
</script>
<template> <FullCalendar defaultView="dayGridMonth" :plugins="calendarPlugins" /> </template>
<style lang='less'> //用什么插件必須引入相應的樣式表,否則不能正常顯示 @import '~@fullcalendar/core/main.css'; @import '~@fullcalendar/daygrid/main.css'; </style>
功能定制
為了完成復雜功能,需要引用更多插件,插件列表:
https://fullcalendar.io/docs/plugin-index
語言設置簡體中文
<FullCalendar locale="zh-cn" />
如果表頭加了button的話,button文字要單獨做處理,給每個button的英文名稱加一個中文的映射,例:
<FullCalendar
:header="{
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
}"
:buttonText="buttonText"
/>
data () {
return {
buttonText: {
today: '今天',
month: '月',
week: '周',
day: '天'
}
}
}
點擊日歷添加事件
想要觸發(fā)dateClick事件必須先安裝引用interaction插件,文檔鏈接:https://fullcalendar.io/docs/dateClick
npm install --save @fullcalendar/interaction
<FullCalendar @dateClick="handleDateClick" />
handleDateClick (arg) {
if (confirm('Would you like to add an event to ' + arg.dateStr + ' ?')) {
this.calendarEvents.push({ // add new event data
title: 'New Event',
start: arg.date,
allDay: arg.allDay
})
}
}
點擊事件查看詳情
<FullCalendar @eventClick="handleEventClick" />
handleEventClick (info) {
alert('Event: ' + info.event.title)
}
完整例子在我的github項目里,項目地址:https://github.com/Inspiration1/asteroid
官方文檔:
https://fullcalendar.io/docs/vue
https://fullcalendar.io/docs#toc
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
vue3使用vueup/vue-quill富文本、并限制輸入字數(shù)的方法處理
這篇文章主要介紹了vue3使用vueup/vue-quill富文本、并限制輸入字數(shù),本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03

