詳解element-ui動態(tài)限定的日期范圍選擇器代碼片段
何開此題
我是一個碼農(nóng),緣起就是這次需求遇到了之前實現(xiàn)過的功能細節(jié),不想再從頭翻組件文檔實現(xiàn)一遍,最好是直接拷貝粘貼。
細節(jié)
picker-options 設定規(guī)則:時間范圍最大可選擇30天, 最晚時間為今天。
element-ui 的日期選擇器的組件是 el-date-picker.
設定 pickerOptions2,
data() {
return {
pickerOptions2: {
disabledDate: theDate => {
const oneDay = 3600 * 1000 * 24
const current = theDate.getTime()
const now = Date.now()
const condition1 = current > now
if (!this.minDateTimestamp) return condition1
const pickerRangeNum = 30
// 時間范圍最大可選擇30天,最晚時間為今天
const lastMonthBegin = this.minDateTimestamp
const lastMonthEnd = lastMonthBegin + pickerRangeNum * oneDay
return (
condition1 || current < lastMonthBegin || current > lastMonthEnd
)
},
onPick: ({ maxDate, minDate }) => {
this.minDateTimestamp = minDate.getTime()
if (maxDate) {
this.minDateTimestamp = 0
}
},
},
}
},
模板的設定,
<template> <el-date-picker class="form-item-control" v-model="qo2.dateRange2" type="daterange" range-separator=" 至 " start-placeholder="開始日期" end-placeholder="結(jié)束日期" placeholder="請選擇時間段" :picker-options="pickerOptions2" /> </template>
總結(jié)
element-ui 動態(tài)限定的日期范圍選擇器,再回首,不用愁。
到此這篇關于element-ui動態(tài)限定的日期范圍選擇器代碼片段的文章就介紹到這了,更多相關element-ui動態(tài)限定的日期范圍選擇器代碼片段內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Vue axios 將傳遞的json數(shù)據(jù)轉(zhuǎn)為form data的例子
今天小編就為大家分享一篇Vue axios 將傳遞的json數(shù)據(jù)轉(zhuǎn)為form data的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10

