FullCalendar-vue demo例子
FullCalendar-vue demo例子
一、 样图
1. 月视图
2. 周视图
3. 日视图
二、 依赖
1. 在package.json中引入依赖
"dependencies": {
"@fullcalendar/core": "^4.3.1",
"@fullcalendar/moment": "^5.5.0",
"@fullcalendar/daygrid": "^5.5.0",
"@fullcalendar/interaction": "^5.5.0",
"@fullcalendar/timegrid": "^5.5.0",
"@fullcalendar/vue": "^5.5.0"
}
2. 执行以下命令下载依赖
npm install --save @fullcalendar/vue @fullcalendar/daygrid @fullcalendar/timegrid @fullcalendar/moment @fullcalendar/interaction
三、代码
1. demo代码
<template>
<div class='demo-app'>
<div class='demo-app-main'>
<FullCalendar class='demo-app-calendar' :options='calendarOptions'>
<template v-slot:eventContent='arg'>
<b>{{ arg.timeText }}</b>
<i>{{ arg.event.title }}</i>
</template>
</FullCalendar>
</div>
</div>
</template>
<script>
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import timeGridPlugin from '@fullcalendar/timegrid'
import interactionPlugin from '@fullcalendar/interaction'
import { INITIAL_EVENTS, createEventId } from '../../../event-utils'
export default {
components: {
FullCalendar, // make the <FullCalendar> tag available
},
data: function () {
return {
calendarOptions: {
plugins: [
dayGridPlugin,
timeGridPlugin,
interactionPlugin, // needed for dateClick
],
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay',
},
initialView: 'dayGridMonth',
initialEvents: INITIAL_EVENTS, // alternatively, use the `events` setting to fetch from a feed
editable: true,
selectable: true,
selectMirror: true,
dayMaxEvents: true,
weekends: true,
select: this.handleDateSelect,
eventClick: this.handleEventClick,
eventsSet: this.handleEvents,
height: 700, // 日历高度
locale: 'zh-cn',
allDaySlot: false, //allday 整天的日程是否显示
// slotDuration:'01:30:00',//在agenda的视图中, 两个时间之间的间隔(分钟)
scrollTime: '09:00:00', //当切换到agenda时,初始滚动条滚动到的时间位置,默认在6点钟的位置
firstDay: 1,
minTime: '06:00:00', //设置显示的时间从几点开始
maxTime: '21:00:00', //设置显示的时间从几点结束
slotLabelFormat: {
hour: 'numeric',
minute: '2-digit',
hour12: false,
}, //确定将在议程视图的垂直轴上显示的时间文本。
businessHours: {
dow: [1, 2, 3, 4,5], // 周一 - 周四
start: '10:00', // 上午10点开始
end: '18:00', // 下午18点结束
},
slotEventOverlap: false, // 设置日程视图中的事件是否可以重叠
agendaEventMinHeight: true,
/* you can update a remote database when these fire:
eventAdd:
eventChange:
eventRemove:
*/
},
currentEvents: [],
}
},
methods: {
handleWeekendsToggle() {
this.calendarOptions.weekends = !this.calendarOptions.weekends // update a property
},
handleDateSelect(selectInfo) {
let title = prompt('Please enter a new title for your event')
let calendarApi = selectInfo.view.calendar
calendarApi.unselect() // clear date selection
if (title) {
calendarApi.addEvent({
id: createEventId(),
title,
start: selectInfo.startStr,
end: selectInfo.endStr,
allDay: selectInfo.allDay,
})
}
},
handleEventClick(clickInfo) {
if (
confirm(
`Are you sure you want to delete the event '${clickInfo.event.title}'`
)
) {
clickInfo.event.remove()
}
},
handleEvents(events) {
this.currentEvents = events
},
},
}
</script>
<style lang='css'>
b {
/* used for event dates/times */
margin-right: 3px;
}
.demo-app {
display: flex;
min-height: 100%;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
font-size: 14px;
}
.demo-app-sidebar {
width: 300px;
line-height: 1.5;
background: #eaf9ff;
border-right: 1px solid #d3e2e8;
}
.demo-app-sidebar-section {
padding: 2em;
}
.demo-app-main {
flex-grow: 1;
padding: 3em;
}
.fc {
/* the calendar root */
max-width: 1100px;
margin: 0 auto;
}
</style>
2. event-utils.js
let eventGuid = 0
let todayStr = new Date().toISOString().replace(/T.*$/, '') // YYYY-MM-DD of today
export const INITIAL_EVENTS = [
{
id: createEventId(),
title: 'All-day event',
start: todayStr
},
{
id: createEventId(),
title: 'Timed event',
start: todayStr + 'T12:00:00'
}
]
export function createEventId() {
return String(eventGuid++)
}
版权声明:本文为qq_45433217原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
THE END