<el-date-picker
v-if="timeRadio==3"
v-model="value6"
@change="changeMonth"
:picker-options="pickerOptionsYearMonth"
format="yyyy年M月"
type="month"
placeholder="选择日期">
</el-date-picker>
data() {
return {
pickerOptionsYearMonth:this.banTime(),
}
}
使用:picker-opyions的定义的函数来控制月份的选择
banTime() {
return {
disabledDate(time) {
const date = new Date()
const year = date.getFullYear()
let month = date.getMonth() + 1
if (month >= 1 && month <= 9) {
month = '0' + month
}
const currentDate = year.toString() + month.toString()
const timeYear = time.getFullYear()
let timeMonth = time.getMonth() + 1
if (timeMonth >= 1 && timeMonth <= 9) {
timeMonth = '0' + timeMonth
}
const timeDate = timeYear.toString() + timeMonth.toString()
return currentDate <= timeDate
}
}
},
运行效果: