vue-event-calendar是一款簡單小巧的事件日曆組件,針對Vue2開發。樣式美觀,且響應式。
在線例子javascript
npm install vue-event-calendar --save
import 'vue-event-calendar/dist/style.css' //1.1.10以後的版本,css被放在了單獨的文件中,方便替換 import vueEventCalendar from 'vue-event-calendar' Vue.use(vueEventCalendar, {locale: 'en'}) //能夠設置語言,支持中文和英文
<template> <vue-event-calendar :events="demoEvents" @monthChanged="" @dayChanged=""></vue-event-calendar> </template> <script> export default { data () { return { demoEvents: [{ date: '2016/12/15', title: 'eat', desc: 'longlonglong description' },{ date: '2016/11/12', title: 'this is a title' }] } }, methods: { monthChange (month) { console.log(month) }, dayChange (day) { console.log(day) } } } </script>
vue-event-calendar容許自定義事件模版,可是這個功能須要Vue 2.1.0版本以上才能夠使用。緣由是我試用了2.1.0以上纔有的新功能做用域插槽(Scoped Slots)。css
<template> <vue-event-calendar :events="demoEvents"> <template scope="props"> <div v-for="(event, index) in props.showEvents" class="event-item"> <!-- 這裏拿到的是傳入的單個event全部數據 --> {{event}} </div> </template> </vue-event-calendar> </template> <script> export default { data () { return { demoEvents: [{ date: '2016/12/15', title: 'eat', desc: 'longlonglong description' },{ date: '2016/11/12', title: 'this is a title' }] } } } </script>
能夠監聽的事件有兩個,選擇了哪天和當月是哪月,當發生改變時,會觸發監聽函數。函數中的回調參數爲改變後的日期。vue
<template> <vue-event-calendar :events="demoEvents" @day-changed="handleDayChanged" @month-changed="handleMonthChanged"> </vue-event-calendar> </template>
// 當 Vue.use時, 能夠設置的參數 { locale: 'en', color: 'black', //Set main color className: 'Custom className for current clicked date', // (default: 'selected-day') weekStartOn: 'week Start on which day' // Can be: 1, 2, 3, 4, 5, 6, 0 (default: 0) }
// 下個月 this.$EventCalendar.nextMonth()
// 上個月 this.$EventCalendar.preMonth()
//到指定日期 this.$EventCalendar.toDate('2016/11/12')
能夠看我寫的Demojava
能夠在github直接clone個人項目而後執行以下命令繼續二次開發或發版,歡迎star&&issuegit
npm run dev //develop npm run build //production