1.1.81 • Published 4 years ago

vue2-event-calendar v1.1.81

Weekly downloads
124
License
MIT
Repository
github
Last release
4 years ago

Vue2 Calendar Component

Full calendar base on Vue2 and dayjs. Support month and week view. Custom date item style with scopeSlots.

中文文档

📺Live demo

Install

// npm
npm install vue2-event-calendar --save

// yarn
yarn add vue2-event-calendar

Import and Usage

Import

// import component
import 'vue2-event-calendar/default.css'
import Calendar from 'vue2-event-calendar'
Vue.component('Calendar', Calendar)

Or import as a component

import 'vue2-event-calendar/default.css'
import { Calendar } from 'vue2-event-calendar'
// ...

export default {
  components: { Calendar }
}

Common usage

<!-- template -->
<Calendar startDate="2018-03-07" :dateData="data">
  <div slot="header-left">
    <Button>month</Button>
    <Button>week</Button>
  </div>

  <div
    :class="['calendar-item', { 'is-otherMonth': !isCurMonth }]"
    slot-scope="item"
  >
    <div
      :class="['calendar-item-date']">
      {{item.date.date}}
    </div>
    <div class="calendar-item-name">{{item.data.title}}</div>
  </div>
</Calendar>

Get full control use body slot. Data structure is a matrix and the size is 6*7.

<Calendar startDate="2018-03-07" :dateData="data">
  <div slot="header-left">
    <Button>month</Button>
    <Button>week</Button>
  </div>

  <template v-slot:body="{ data }">
    <transition name="fade">
      <div class="calendar-body-grid" :key="indentifier">
        <div v-for="(row, index) in data"
          :key="index"
          class="calendar-body-row">
          <div v-for="col in row"
            :key="col.date.date"
            :class="['calendar-item', { 'is-otherMonth': !col.isCurMonth }]">
            <div
              :class="['calendar-item-date']">
              {{col.date.date}}
            </div>
            <div class="calendar-item-name">{{col.data.title}}</div>
          </div>
        </div>
      </div>
    </transition>
  </template>
</Calendar>

Customize header use renderHeader props

<!-- template -->
<Calendar
  startDate="2018-03-07"
  :renderHeader="renderHeader"
  :dateData="data">
  <!-- content -->
</Calendar>
export default {
  // ...
  methods: {
    renderHeader({ prev, next, selectedDate }) {
      const h = this.$createElement

      const prevButton = h('div', {
        on: {
          click: prev
        }
      }, ['prev'])

      const nextButton = h('div', {
        on: {
          click: next
        }
      }, ['next'])

      return h('div', [prevButton, selectedDate, nextButton])
    }
  }
}

Props

parameterdescriptiontypedefaultacceptable value
startDatecalendar start dateString, timestamp, Datenew Date()
dateDatacalendar data, item object must have date params to match date(params key can use matchKey to modify)Object, Array
matchKeyif dateData is Array, specify which key of dateData object as calendar date match keyStringdate
localeset weekdays locale text, custom this text use weekDateShort props. If want to use custom local, use weekLocaleData customize you localeStringenzh-cn, en
weekLocaleDataset body weekdays text, begin with sunday, if set this props, locale will be not workarray
firstDaystart day of the week, 0 to 6, 0 as SundayNumber00 - 6
modecomponent view modeStringmonthmonth, week
prefixClscomponent style namespaceStringvue-calendar
renderHeaderredner function for headerFunction({ prev, next, selectedDate })

Event Props

parameterdescriptionparams
onMonthChangetrigger when calendar date change(date) parameter has two key startDay and endDay of selected month
onPrevtrigger after clicking the prev buttonsame as onMonthChange param
onNexttrigger after clicking the next buttonsame as onMonthChange param

Methods

namedescriptionparams
changeDateset calendar display month(date) accept String or Date Object

Slots

namedescription
header-leftheader left panel
header-rightheader right panel

Scope-slots

namedescription
defaultcustom content for date item, the scope param is { isPrevMonth, isPrevLastDay, isNextMonth, isNextFirstDay, isToday, isCurMonth, data, date }, { data } is an Array, include all matching date data
bodyreturn all date item in scope param, data structure is a 6*7 matrix, and the date item is same as default scope slot
1.1.81

4 years ago

1.1.80

5 years ago

1.1.72

5 years ago

1.1.71

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.0.6

5 years ago

1.0.4

5 years ago

1.0.0

5 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.6

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.9

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago