项目场景:
element-el-date-picker 时间选择器当前月之后不可选
<el-date-picker
v-model="dataTime"
type="month"
value-format="yyyy-MM"
:picker-options="pickerOptions"
@change="dateChange"
placeholder="选择月"
>
</el-date-picker>
data() {
return {
pickerOptions: this.getTime(),
};
},
methods: {
getTime() {
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;
},
};
},
}
导入
代码仅供参考。