vue:element.ui中中日期时间范围选择控件怎么设置选择的范围,不能跨月选择 10
展开全部
配置规则:
pickerOptions: {
onPick: ({ maxDate, minDate }) => {
this.choiceDate = minDate.getTime()
if (maxDate) {
this.choiceDate = ''
}
},
disabledDate: (time) => {
const self = this;
if (!!self.choiceDate) {
const startDay = (new Date(self.choiceDate).getDate() - 1) * 24 * 3600 * 1000;
const endDay = (new Date(
new Date(self.choiceDate).getFullYear(),
new Date(self.choiceDate).getMonth() + 1,
0
).getDate() - new Date(self.choiceDate).getDate()) * 24 * 3600 * 1000;
let minTime = self.choiceDate - startDay;
let maxTime = self.choiceDate + endDay;
return time.getTime() < minTime || time.getTime() > maxTime
}
}
},
choiceDate: ''
========================================================
template里面
<el-date-picker
:picker-options="pickerOptions"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyy-MM-dd"
type="daterange"
align="right"></el-date-picker>
pickerOptions: {
onPick: ({ maxDate, minDate }) => {
this.choiceDate = minDate.getTime()
if (maxDate) {
this.choiceDate = ''
}
},
disabledDate: (time) => {
const self = this;
if (!!self.choiceDate) {
const startDay = (new Date(self.choiceDate).getDate() - 1) * 24 * 3600 * 1000;
const endDay = (new Date(
new Date(self.choiceDate).getFullYear(),
new Date(self.choiceDate).getMonth() + 1,
0
).getDate() - new Date(self.choiceDate).getDate()) * 24 * 3600 * 1000;
let minTime = self.choiceDate - startDay;
let maxTime = self.choiceDate + endDay;
return time.getTime() < minTime || time.getTime() > maxTime
}
}
},
choiceDate: ''
========================================================
template里面
<el-date-picker
:picker-options="pickerOptions"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyy-MM-dd"
type="daterange"
align="right"></el-date-picker>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询