vue-event-calendar 事件日历插件

发布时间:2019-05-28 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了vue-event-calendar 事件日历插件脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

vue-event-calendar

vue-event-calendar是一款简单小巧的事件日历组件,针对Vue2开发。样式美观,且响应式。
在线例子

npm version

依赖

  • vue: ^2.0.0

使用方法

安装

 npm install vue-event-calendar --save

入口 Main.js

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)。

<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>

组件事件

可以监听的事件有两个,选择了哪天和当月是哪月,当发生改变时,会触发监听函数。函数中的回调参数为改变后的日期。

<template>
  <vue-event-calendar
    :events="demoEvents"
    @day-changed="handleDayChanged"
    @month-changed="handleMonthChanged">
  </vue-event-calendar>
</template>

Options

@H_777_336@ // 当 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) } @H_266_360@API
// 下个月
this.$EventCalendar.nextMonth()
// 上个月
this.$EventCalendar.preMonth()
//到指定日期
this.$EventCalendar.toDate('2016/11/12')

可以看我写的Demo

开发

可以在github直接clone我的项目然后执行如下命令继续二次开发或发版,欢迎star&&issue

npm run dev  //develop
npm run build //production

Change log

1.3.6 -> 1.4.0
  • 去除了当天的背景,改用一个在日期下面的小点替代
  • 增加选中日期样式

脚本宝典总结

以上是脚本宝典为你收集整理的vue-event-calendar 事件日历插件全部内容,希望文章能够帮你解决vue-event-calendar 事件日历插件所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。