- 首先下载安装所需要的包
npm i @fullcalendar/daygrid @fullcalendar/interaction @fullcalendar/vue
- 引入到当前vue 组件中
import FullCalendar from "@fullcalendar/vue";
import dayGridPlugin from "@fullcalendar/daygrid";
import interactionPlugin from "@fullcalendar/interaction";
- 注册组件
<FullCalendar :options="calendarOptions" />
components: {
FullCalendar,
},
- 配置参数
calendarOptions: {
locale: "zh",
buttonText: {
today: "今天",
month: "月视图",
week: "周视图",
},
plugins: [dayGridPlugin, interactionPlugin],
headerToolbar: {
left: "prev,next today",
center: "title",
right: "dayGridMonth,dayGridWeek",
},
initialView: "dayGridMonth",
editable: false,
selectable: true,
dateClick: this.handleDateClick,
events: [
{title: "放假",
start:"2021-03-05",
end:"2021-03-08",
id: "bianhao1111",
color: "#f00",
}
],
eventClick: this.handleEventClick,
},
- 效果图如下所示