在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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
vue?+?ele?實現(xiàn)下拉選擇框和下拉多選選擇框處理方案
這篇文章主要介紹了vue?+?ele?實現(xiàn)下拉選擇框和下拉多選選擇框處理方案,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-08-08vue element實現(xiàn)將表格單行數(shù)據(jù)導出為excel格式流程詳解
這篇文章主要介紹了vue element實現(xiàn)將表格單行數(shù)據(jù)導出為excel格式流程,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧2022-12-12vue中提示$index is not defined錯誤的解決方式
這篇文章主要介紹了vue中提示$index is not defined錯誤的解決方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09基于vue3?vue-cli4?線上部署及優(yōu)化的問題
這篇文章主要介紹了基于vue3?vue-cli4?線上部署及優(yōu)化的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06