一般在实际开发场景中我们需要对时间选择做一些限制,如不能选择今天之前的时间、不能选择今天以后的日期、限制日期不能大于开始日期等等。
日期组件
<el-date-picker
v-model="value1"
type="date"
placeholder="选择日期"
:picker-options="pickerOptions0"
>
</el-date-picker>
1.选择今天及今天以后的日期
data(){
return {
value1: '',
pickerOptions0: {
disabledDate(time){
return time.getTime() < Date.now() - 8.64e7;
}
}
}
}
2. 选择今天及今天以前的日期
data (){
return {
value1: '',
pickerOptions0: {
disabledDate(time) {
return time.getTime() > Date.now() - 8.64e6
}
},
}
}
3. 选择今天之后的日期(不能选择当天)
data (){
return {
value1: '',
pickerOptions0: {
disabledDate(time) {
return time.getTime() < Date.now();
}
},
}
}
4. 选择今天之前的日期(不能选择当天)
data (){
return {
value1: '',
pickerOptions0: {
disabledDate(time) {
return time.getTime() > Date.now() - 8.64e7;
}
},
}
}
两个日期组件
<el-date-picker
v-model="value1"
type="date"
placeholder="开始日期"
:picker-options="pickerOptions0">
</el-date-picker>
<el-date-picker
v-model="value2"
type="date"
placeholder="结束日期"
:picker-options="pickerOptions1">
</el-date-picker>
两日日期之间的日期
data(){
return {
value1: '',
value2: '',
pickerOptions0: {
disabledDate: (time) => {
if (this.value2 != "") {
return time.getTime() > Date.now() || time.getTime() > this.value2;
} else {
return time.getTime() > Date.now();
}
}
},
pickerOptions1: {
disabledDate: (time) => {
return time.getTime() < this.value1 || time.getTime() > Date.now();
}
},
}
}
转载自: https://www.cnblogs.com/xjcjcsy/p/7977966.html
作者:rookie.he(kuke_kuke)
博客链接:http://blog.csdn.net/qq_33599109
欢迎关注支持,谢谢!