2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-09 02:22:26 +03:00
Files
vue2-datepicker/src/panel/year.js
T
2018-06-16 10:11:13 +08:00

29 lines
701 B
JavaScript

export default {
name: 'panelYear',
props: {
value: null,
firstYear: Number
},
methods: {
selectYear (year) {
this.$emit('select', year)
}
},
render (h) {
// 当前年代
const firstYear = Math.floor(this.firstYear / 10) * 10
const currentYear = this.value && new Date(this.value).getFullYear()
const years = Array.apply(null, { length: 10 }).map((_, i) => {
const year = firstYear + i
return <span
class={{
'cell': true,
'actived': currentYear === year
}}
onClick={this.selectYear.bind(this, year)}
>{year}</span>
})
return <div class="mx-panel mx-panel-year">{years}</div>
}
}