element 日歷組件源碼片段:
/**
點擊上月今天下月
*/
selectDate(type) {
if (validTypes.indexOf(type) === -1) {
throw new Error(`invalid type ${type}`);
}
let day = '';
if (type === 'prev-month') {
// 上月第一天
day = `${this.prevMonthDatePrefix}-01`;
} else if (type === 'next-month') {
// 下月第一天
day = `${this.nextMonthDatePrefix}-01`;
} else {
// 今天
day = this.formatedToday;
}
if (day === this.formatedDate) return;
this.pickDay(day);
},
方法:
<el-calendar ref="calen1" v-model="calendarDate"></el-calendar>
this.$refs.calen1.selectDate("today")