From bc80708787ea0b955e1cb7717ba855c988a6f635 Mon Sep 17 00:00:00 2001 From: mxie <15623530290@163.com> Date: Mon, 6 Aug 2018 12:07:04 +0800 Subject: [PATCH] feat: add event 'change-calendar-year' 'change-calendar-month' --- src/calendar.vue | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/calendar.vue b/src/calendar.vue index d87924c..ca49583 100644 --- a/src/calendar.vue +++ b/src/calendar.vue @@ -290,14 +290,34 @@ export default { changeCalendarMonth (month) { this.now = new Date(this.calendarYear, month) }, + getSibling () { + const calendars = this.$parent.$children.filter(v => v.$options.name === this.$options.name) + const index = calendars.indexOf(this) + const sibling = calendars[index ^ 1] + return sibling + }, handleIconMonth (flag) { - this.changeCalendarMonth(this.calendarMonth + flag) + const month = this.calendarMonth + this.changeCalendarMonth(month + flag) + this.$parent.$emit('change-calendar-month', { + month, + flag, + vm: this, + sibling: this.getSibling() + }) }, handleIconYear (flag) { if (this.panel === 'YEAR') { this.changePanelYears(flag) } else { - this.changeCalendarYear(this.calendarYear + flag) + const year = this.calendarYear + this.changeCalendarYear(year + flag) + this.$parent.$emit('change-calendar-year', { + year, + flag, + vm: this, + sibling: this.getSibling() + }) } }, handleBtnYear () {