JS部分:
data() {
return {
pickerOptions: {
disabledDate(time) {
/**
* 大于当前月分的日期不可选
*/
//获取时间,当前的月份
const date = new Date()
const year = date.getFullYear()
let month: any = date.getMonth() + 1
if (month >= 1 && month <= 9) {
month = '0' + month
}
const currentdate = year.toString() + month.toString()
// 获取时间选择器上选择的月份
const timeyear = time.getFullYear()
let timemonth:any = time.getMonth() + 1
if (timemonth >= 1 && timemonth <= 9) {
timemonth = '0' + timemonth
}
const timedate = timeyear.toString() + timemonth.toString()
return time.getTime() < new Date(new Date().getFullYear().toString()).getTime() || currentdate <= timedate
},
},
value1: '',
}
}
HTML部分:
<el-date-picker
v-model="time"
type="month"
size="mini"
popper-class="yy-time"
value-format="yyyyMM"
placeholder="选择年月"
@change="fetchData"
:style="{ width: getSwitchWIdth(120) + 'px' }"
:clearable="false"
:picker-options="pickerOptions"
></el-date-picker>