FullCalendar (全日历)Vue组件的使用
FullCalendar日历组件支持Vue React Angular Javascript
今天小编给大家分享的是在Vue2中的使用
如果使用的Vue2的框架
npm install --save @fullcalendar/core @fullcalendar/vue
如果使用的是Vue3的框架
npm install --save @fullcalendar/core @fullcalendar/vue3
示例代码:
<template>
<div>
<FullCalendar :options="calendarOptions" />
</div>
</template>
<script>
import FullCalendar from "@fullcalendar/vue";
import dayGridPlugin from "@fullcalendar/daygrid";
import interactionPlugin from "@fullcalendar/interaction";
import timeGridPlugin from "@fullcalendar/timegrid";
import listPlugin from '@fullcalendar/list';
export default {
components: {
FullCalendar, // make the <FullCalendar> tag available
},
data() {
return {
calendarOptions: {
plugins: [
dayGridPlugin, //月视图插件
interactionPlugin,
timeGridPlugin, //时间视图插件
listPlugin, //列表视图插件
],
initialView: "dayGridWeek", //dayGridMonth 月视图 timeGridWeek 时间视图 dayGridWeek日视图
locale: "zh-cn", // 设置语言
// initialView: 'dayGridMonth'
nowIndicator: true, //根据当前事件显示刻度线
headerToolbar: {
left: "prev,next today",
center: "title",
right: "dayGridMonth,dayGridWeek,dayGrid",
},
events: Array.from({ length: 50 }).map(_=>{
return { title: "事件" + Math.random(), start: new Date().getTime() + Math.random() * 1000000 }
}), //试图显示的数据
eventDragStart: (info) => {
console.log(info);
console.log("拖拽开始");
},
eventDrop: (info) => {
// TODO 这里可以修改拖动元素的原有时间
console.log("====================================");
console.log(info, "拖拽结束");
console.log("====================================");
},
eventMouseEnter: (mouseEnterInfo) => {
console.log("====================================");
console.log(mouseEnterInfo, "鼠标移入事件");
console.log("====================================");
},
eventMouseLeave: (eventMouseLeave) => {
console.log("====================================");
console.log(eventMouseLeave, "鼠标移出事件");
console.log("====================================");
},
nowIndicatorDidMount: (info) => {
console.log("====================================", info);
},
eventClick: (eventClickInfo) => {
console.log("====================================");
console.log(eventClickInfo, "鼠标点击事件");
console.log(eventClickInfo.event.id);
let INdex = this.calendarOptions.events.findIndex((item) => {
return item.id == eventClickInfo.event.id;
});
if (INdex != -1) {
this.calendarOptions.events.splice(INdex, 1);
}
console.log("====================================");
},
selectable: true,
eventStartEditable: true, //允许通过拖动来编辑事件的开始时间。
eventResizableFromStart:true,//用户是否可以从事件的起始边缘调整事件的大小。
eventDurationEditable:true,// 允许通过调整大小来编辑事件的持续时间。
// selectMirror: true,
editable: true, //是否允许修改日历
droppable: true, // 在日历之间拖拽
// unselectAuto:false,//取消用户自动选择
dragScroll: true, // 拖拽滚动
// unselectCancel:'',
selectOverlap: function (event) {
console.log("====================================");
console.log(event);
console.log("====================================");
//选择重叠
return event.display === "background";
},
dateClick: function (info) {
/*日期选择*/
console.log(info);
// alert("Clicked on: " + info.dateStr);
// alert(
// "Coordinates: " + info.jsEvent.pageX + "," + info.jsEvent.pageY
// );
// alert("Current view: " + info.view.type);
// // change the day's background color just for fun
// info.dayEl.style.backgroundColor = "red";
},
select: (selectionInfo) => {
let object = {
id: this.calendarOptions.events.length + 1,
start: selectionInfo.start,
end: selectionInfo.end,
title: "xxxxx",
};
//选中事件
console.log(selectionInfo);
this.calendarOptions.events.push(object);
},
unselect: (jsEvent, view) => {
console.log("====================================取消");
console.log(jsEvent, view);
console.log("====================================");
},
buttonText: {
// 设置按钮
today: "今天",
month: "月",
week: "周",
dayGrid: "天",
},
},
};
},
};
</script>
<style lang="scss" scoped></style>
目前知识钻研了一部分的属性,感兴趣的小伙伴可以自己根据官网的文档进行尝试