vue日期選擇框之時(shí)間范圍的使用介紹
更新時(shí)間:2022年05月31日 11:03:29 作者:itfallrain
這篇文章主要介紹了vue日期選擇框之時(shí)間范圍的使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
vue日期選擇框之時(shí)間范圍
實(shí)現(xiàn)效果如下

<a-col :xl="8" :lg="16" :md="24" :sm="32">
<a-form-item label="時(shí)間" >
<a-range-picker
style="width: 350px"
v-model="queryParam.createTimeRange"
:disabled-time="disabledRangeTime"
:show-time="{
hideDisabledOptions: true,
defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
}"
format="YYYY-MM-DD HH:mm:ss"
:placeholder="['開(kāi)始時(shí)間', '結(jié)束時(shí)間']"
@change="onDateChange"
@ok="onDateOk"
/>
</a-form-item>
</a-col>1:引入格式化工具
import moment from 'moment'
2:給默認(rèn)值
queryParam:{
createTimeRange:[
moment(new Date(new Date(new Date().toLocaleDateString()).getTime()),'YYYY-MM-DD HH:mm:ss'),
moment(new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1),'YYYY-MM-DD HH:mm:ss')
]
},3:methods書(shū)寫(xiě)的方法
methods: {
moment,
//時(shí)間相關(guān)函數(shù) start
onDateChange: function (value, dateString) {
console.log(dateString[0],dateString[1]);
this.queryParam.startTime=dateString[0];
this.queryParam.endTime=dateString[1];
},
onDateOk(value) {
console.log(value);
},
range(start, end) {
const result = [];
for (let i = start; i < end; i++) {
result.push(i);
}
return result;
},
disabledRangeTime(_, type) {
if (type === 'start') {
return {
disabledHours: () => this.range(0, 60).splice(60, 60),
disabledMinutes: () => this.range(0, 60).splice(60, 60),
disabledSeconds: () => this.range(0, 60).splice(60, 60),
};
}
return {
disabledHours: () => this.range(0, 60).splice(60, 60),
disabledMinutes: () => this.range(0, 60).splice(60, 60),
disabledSeconds: () => this.range(0, 60).splice(60, 60),
};
},
//時(shí)間相關(guān)函數(shù) end
}vue日期控件解析
<el-form-item label="有效期限" >
<el-col :span="6">
<el-form-item>
<el-date-picker
type="date"
placeholder="選擇日期"
value-format="yyyy-MM-dd 00:00:00"
v-model="effectiveStartTime"
:picker-options="pickerOptionsStart"
></el-date-picker>
</el-form-item>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="6">
<el-form-item>
<el-date-picker
placeholder="選擇日期"
value-format="yyyy-MM-dd 00:00:00"
v-model="effectiveEntTime"
:picker-options="pickerOptionsEnd"
></el-date-picker>
</el-form-item>
</el-col>
</el-form-item> 以上template視圖層
return {
effectiveEntTime: "",
effectiveEntTime: "",
pickerOptionsStart: {
//開(kāi)始有效期
disabledDate: (time) => {
if (this.effectiveEntTime) {
return time.getTime() > new Date(this.effectiveEntTime).getTime();
}
},
},
pickerOptionsEnd: {
//結(jié)束有效期
disabledDate: (time) => {
if (this.effectiveStartTime) {
return (
time.getTime() - 3600 * 1000 * 24 <
new Date(this.effectiveStartTime).getTime() - 86400000 ||
Date.now() - 3600 * 1000 * 24 > time.getTime()
);
}
},
},
};script 邏輯層
效果


以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue使用echarts詞云圖的實(shí)戰(zhàn)記錄
這篇文章主要給大家介紹了關(guān)于vue使用echarts詞云圖的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05
Vue系列之Element?UI表單自定義校驗(yàn)規(guī)則
表單校驗(yàn)是注冊(cè)環(huán)節(jié)中必不可少的操作,表單校驗(yàn)可以提醒用戶填寫(xiě)數(shù)據(jù)規(guī)則以確保用戶提交數(shù)據(jù)的效性,也可以防止用戶因誤操作而占用服務(wù)器資源,這篇文章主要給大家介紹了關(guān)于Vue系列之Element?UI表單自定義校驗(yàn)規(guī)則的相關(guān)資料,需要的朋友可以參考下2022-09-09
Vue狀態(tài)管理庫(kù)Pinia詳細(xì)介紹
這篇文章主要介紹了Vue3-pinia狀態(tài)管理,pinia是 vue3 新的狀態(tài)管理工具,簡(jiǎn)單來(lái)說(shuō)相當(dāng)于之前 vuex,它去掉了 Mutations 但是也是支持 vue2 的,需要的朋友可以參考下2022-08-08
vue組件props不同數(shù)據(jù)類型傳參的默認(rèn)值問(wèn)題
這篇文章主要介紹了vue組件props不同數(shù)據(jù)類型傳參的默認(rèn)值問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
vue3循環(huán)設(shè)置ref并獲取的解決方案
我們?cè)谄綍r(shí)做業(yè)務(wù)的時(shí)候,父子組件通信會(huì)經(jīng)常用到ref,這篇文章主要給大家介紹了關(guān)于vue3循環(huán)設(shè)置ref并獲取的解決方案,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-02-02
Vue 重置data的數(shù)據(jù)為初始狀態(tài)操作
這篇文章主要介紹了Vue 重置data的數(shù)據(jù)為初始狀態(tài)操作方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2021-03-03

