在Vue項(xiàng)目中用fullcalendar制作日程表的示例代碼
前言
最近老牌日歷插件fullcalendar更新了v4版本,而且添加了Vue支持,所以用最新的fullcalendar v4制作一個(gè)完整日歷體驗(yàn)一下,效果圖:
安裝
FullCalendar的功能被分解為“插件”。如果您需要它提供的功能,您只需要包含一個(gè)插件。
也就是說,F(xiàn)ullCalendar v4所有插件都得單獨(dú)安裝引用。
npm install --save @fullcalendar/vue @fullcalendar/core @fullcalendar/daygrid
引用并初始化
引用、注冊(cè)FullCalendar組件,得到一個(gè)月視圖的日歷。
<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'> //用什么插件必須引入相應(yīng)的樣式表,否則不能正常顯示 @import '~@fullcalendar/core/main.css'; @import '~@fullcalendar/daygrid/main.css'; </style>
功能定制
為了完成復(fù)雜功能,需要引用更多插件,插件列表:
https://fullcalendar.io/docs/plugin-index
語言設(shè)置簡體中文
<FullCalendar locale="zh-cn" />
如果表頭加了button的話,button文字要單獨(dú)做處理,給每個(gè)button的英文名稱加一個(gè)中文的映射,例:
<FullCalendar :header="{ left: 'prev,next today', center: 'title', right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek' }" :buttonText="buttonText" />
data () { return { buttonText: { today: '今天', month: '月', week: '周', day: '天' } } }
點(diǎn)擊日歷添加事件
想要觸發(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 }) } }
點(diǎn)擊事件查看詳情
<FullCalendar @eventClick="handleEventClick" />
handleEventClick (info) { alert('Event: ' + info.event.title) }
完整例子在我的github項(xiàng)目里,項(xiàng)目地址:https://github.com/Inspiration1/asteroid
官方文檔:
https://fullcalendar.io/docs/vue
https://fullcalendar.io/docs#toc
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
詳解新手使用vue-router傳參時(shí)注意事項(xiàng)
這篇文章主要介紹了詳解新手使用vue-router傳參時(shí)注意事項(xiàng),詳細(xì)的介紹了幾種常見錯(cuò)誤,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06vue?+?ele?實(shí)現(xiàn)下拉選擇框和下拉多選選擇框處理方案
這篇文章主要介紹了vue?+?ele?實(shí)現(xiàn)下拉選擇框和下拉多選選擇框處理方案,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-08-08vue element實(shí)現(xiàn)將表格單行數(shù)據(jù)導(dǎo)出為excel格式流程詳解
這篇文章主要介紹了vue element實(shí)現(xiàn)將表格單行數(shù)據(jù)導(dǎo)出為excel格式流程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-12-12vue中提示$index is not defined錯(cuò)誤的解決方式
這篇文章主要介紹了vue中提示$index is not defined錯(cuò)誤的解決方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-09-09Vue的指令中實(shí)現(xiàn)傳遞更多參數(shù)
這篇文章主要介紹了Vue的指令中實(shí)現(xiàn)傳遞更多參數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05基于vue3?vue-cli4?線上部署及優(yōu)化的問題
這篇文章主要介紹了基于vue3?vue-cli4?線上部署及優(yōu)化的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06