Skip to content

Commit

Permalink
feat(components): [el-calendar] add prev-year and next-year (#3360)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxian521 committed Sep 12, 2021
1 parent f6833e8 commit f2939ae
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/components/calendar/src/index.vue
Expand Up @@ -58,7 +58,12 @@ import DateTable from './date-table.vue'
import type { Dayjs } from 'dayjs'
type DateType = 'prev-month' | 'today' | 'next-month'
type DateType =
| 'prev-month'
| 'next-month'
| 'prev-year'
| 'next-year'
| 'today'
const { ButtonGroup: ElButtonGroup } = ElButton
export default defineComponent({
Expand Down Expand Up @@ -104,6 +109,14 @@ export default defineComponent({
return date.value.add(1, 'month')
})
const prevYearDayjs = computed(() => {
return date.value.subtract(1, 'year')
})
const nextYearDayjs = computed(() => {
return date.value.add(1, 'year')
})
const i18nDate = computed(() => {
const pickedMonth = `el.datepicker.month${date.value.format('M')}`
return `${date.value.year()} ${t('el.datepicker.year')} ${t(pickedMonth)}`
Expand Down Expand Up @@ -242,6 +255,10 @@ export default defineComponent({
day = prevMonthDayjs.value
} else if (type === 'next-month') {
day = nextMonthDayjs.value
} else if (type === 'prev-year') {
day = prevYearDayjs.value
} else if (type === 'next-year') {
day = nextYearDayjs.value
} else {
day = now
}
Expand Down

0 comments on commit f2939ae

Please sign in to comment.