vue-event-calendar-lu

1.3.8 • Public • Published

vue-event-calendar

依赖

  • vue: ^2.0.0

使用方法

安装

 npm install vue-event-calendar-lu --save

入口 Main.js

import 'vue-event-calendar-lu/dist/style.css' //css被放在了单独的文件中,方便替换
import vueEventCalendar from 'vue-event-calendar-lu'
Vue.use(vueEventCalendar, {locale: 'zh'}) //可以设置语言,支持中文和英文

用法示例

<template>
  <vue-event-calendar :events="demoEvents" @monthChanged="" @dayChanged=""></vue-event-calendar>
</template>
 
<script>
export default {
  data () {
    return {
      demoEvents: [{
        date: '2016/11/12', // 必填
        title: 'Foo' // 必填
      }, {
        date: '2016/12/15',
        title: 'Bar',
        desc: 'description',
        customClass: 'disabled highlight' // 自定义日历单元格的Class,会加到对应的日历单元格上
      }]
    }
  },
  methods: {
    monthChange (month) {
      console.log(month)
    },
    dayChange (day) {
      console.log(day)
    }
  }
}
</script>

自定义日期标题

<template>
  <vue-event-calendar :title="title" :events="demoEvents" @dayChanged="handleDayChange"></vue-event-calendar>
</template>

当你使用自定义日历标题的时候,需要注意,标题将被替换成静态的你传入的String,你需要手动监听dayChanged事件去改变title。

自定义事件模版(可以允许你展示更多信息)

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

  // 当 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)
  }

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
  • 去除了当天的背景,改用一个在日期下面的小圆点替代
  • 增加选中日期样式

License

MIT

Package Sidebar

Install

npm i vue-event-calendar-lu

Weekly Downloads

1

Version

1.3.8

License

none

Unpacked Size

174 kB

Total Files

20

Last publish

Collaborators

  • aq7642220