Skip to content

Commit bc80708

Browse files
committed
feat: add event 'change-calendar-year' 'change-calendar-month'
1 parent 6ecfed8 commit bc80708

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/calendar.vue

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,34 @@ export default {
290290
changeCalendarMonth (month) {
291291
this.now = new Date(this.calendarYear, month)
292292
},
293+
getSibling () {
294+
const calendars = this.$parent.$children.filter(v => v.$options.name === this.$options.name)
295+
const index = calendars.indexOf(this)
296+
const sibling = calendars[index ^ 1]
297+
return sibling
298+
},
293299
handleIconMonth (flag) {
294-
this.changeCalendarMonth(this.calendarMonth + flag)
300+
const month = this.calendarMonth
301+
this.changeCalendarMonth(month + flag)
302+
this.$parent.$emit('change-calendar-month', {
303+
month,
304+
flag,
305+
vm: this,
306+
sibling: this.getSibling()
307+
})
295308
},
296309
handleIconYear (flag) {
297310
if (this.panel === 'YEAR') {
298311
this.changePanelYears(flag)
299312
} else {
300-
this.changeCalendarYear(this.calendarYear + flag)
313+
const year = this.calendarYear
314+
this.changeCalendarYear(year + flag)
315+
this.$parent.$emit('change-calendar-year', {
316+
year,
317+
flag,
318+
vm: this,
319+
sibling: this.getSibling()
320+
})
301321
}
302322
},
303323
handleBtnYear () {

0 commit comments

Comments
 (0)