el-date-picker 限制只能选择当年的日期
<template>
<div>
<el-date-picker v-model="dataForm.jjDate" placeholder="奖惩时间" style="width: 240px;" type="datetime"
@change="cDatePicker" :picker-options="expireTimeOption" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
</div>
</template>
<script>
export default {
data() {
return {
dataValidate:'',
dataForm:{
jjDate:''
},
expireTimeOption: {
disabledDate(date) {
//disabledDate 文档上:设置禁用状态,参数为当前日期,要求返回 Boolean
return (
date.getTime() < new Date(new Date().getFullYear(),0,1).getTime() ||
date.getTime() > new Date(new Date().getFullYear(),11,31).getTime()
);
}
}
};
},
methods: {
cDatePicker(vm){
const year= vm.split('-')[0]
const conYear = new Date().getFullYear();
this.dataValidate = "";
if(year !== conYear){
this.dataValidate = "";
}
}
}
}
</script>
<!-- :picker-options="new Date()"-->
<el-date-picker placeholder="请选择账期" v-model="dataForm.waterMonth"
:picker-options="expireTimeOption" type="month" value-format="yyyy-MM"></el-date-picker>
expireTimeOption: {
disabledDate(date) {
//disabledDate 文档上:设置禁用状态,参数为当前日期,要求返回 Boolean
if(new Date().getMonth() == 0){
return (
date.getTime() < new Date(new Date().getFullYear()-1,11,31).getTime() ||
date.getTime() > new Date(new Date().getFullYear(),11,31).getTime()
);
}else {
return (
date.getTime() < new Date(new Date().getFullYear(),0,1).getTime() ||
date.getTime() > new Date(new Date().getFullYear(),11,31).getTime()
);
}
}
},
择善人而交,择善书而读,择善言而听,择善行而从。