0%

element-ui 日期选择器-开始结束日期选择限制

摘要:element-ui 日期选择器-开始结束日期选择限制

代码

最简洁代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 我的卷库-组件-内容头部
<template>
<div>
<el-date-picker
v-model="startDate"
type="date"
placeholder="开始日期"
:picker-options="pickerOptionsStart"
/>
<span>至</span>
<el-date-picker
v-model="endDate"
type="date"
placeholder="结束日期"
:picker-options="pickerOptionsEnd"
/>
</div>
</template>

<script>
export default {
data() {
return {
startDate: '',
endDate: '',
// 开始结束日期限制
pickerOptionsStart: {
disabledDate: time => {
if (this.endDate) {
return time.getTime() > new Date(this.endDate).getTime()
}
}
},
pickerOptionsEnd: {
disabledDate: time => {
if (this.startDate) {
return time.getTime() < new Date(this.startDate).getTime() - 86400000
}
}
}
}
}
}
</script>

<style lang="less" scoped>

</style>

图示

date

[原文链接](### 代码

最简洁代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// 我的卷库-组件-内容头部
<template>
<div>
<el-date-picker
v-model="startDate"
type="date"
placeholder="开始日期"
:picker-options="pickerOptionsStart"
/>
<span>至</span>
<el-date-picker
v-model="endDate"
type="date"
placeholder="结束日期"
:picker-options="pickerOptionsEnd"
/>
</div>
</template>

<script>
export default {
data() {
return {
startDate: '',
endDate: '',
// 开始结束日期限制
pickerOptionsStart: {
disabledDate: time => {
if (this.endDate) {
return time.getTime() > new Date(this.endDate).getTime()
}
}
},
pickerOptionsEnd: {
disabledDate: time => {
if (this.startDate) {
return time.getTime() < new Date(this.startDate).getTime() - 86400000
}
}
}
}
}
}
</script>

<style lang="less" scoped>

</style>

图示

date

原文链接

-------------本文结束感谢您的阅读-------------