ElementPlus 自定義封裝 el-date-picker 的快捷功能示例詳解
需求
分析
我們看到官網(wǎng)上給出的案例如下,但是不太滿足我們用戶想要的快捷功能,因?yàn)椴惶啵虼诵枰覀冏约悍庋b一些,方法如下
外部自定義該組件的快捷內(nèi)容
export const getPickerOptions = () => { const shortcuts = [ { text: '過去1小時(shí)', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 1); return [start, end] }, }, { text: '過去4小時(shí)', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 4); return [start, end] }, }, { text: '過去12小時(shí)', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 12); return [start, end] }, }, { text: '昨天到今天', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24); return [start, end] }, }, { text: '最近一周', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 7) return [start, end] }, }, { text: '最近一個(gè)月', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 30) return [start, end] }, }, { text: '最近三個(gè)月', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 90) return [start, end] }, }, { text: '過去半年', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 183); return [start, end] }, }, { text: '過去3年', value: () => { const end = new Date() const start = new Date() start.setTime(start.getTime() - 3600 * 1000 * 24 * 365 * 3); return [start, end] }, }, ] return shortcuts };
組件中導(dǎo)入并使用
<template> <el-date-picker v-model="editForm_tree.time" type="datetimerange" show-time value-format="YYYY-MM-DD HH:mm:ss" :shortcuts="shortcuts" range-separator="到" start-placeholder="開始時(shí)間" end-placeholder="結(jié)束時(shí)間" /> </template> <script lang="ts" setup> import { onBeforeUnmount, onMounted, ref, watch, watchEffect, computed, reactive, } from 'vue'; import { getPickerOptions } from '@/utils/pickerOptions.js'; const shortcuts = getPickerOptions(); </script>
到此這篇關(guān)于ElementPlus 自定義封裝 el-date-picker 的快捷功能示例詳解的文章就介紹到這了,更多相關(guān)ElementPlus 自定義封裝 el-date-picker內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue清空數(shù)組的幾個(gè)方式(小結(jié))
本文主要介紹了vue清空數(shù)組的幾個(gè)方式,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12Vue動(dòng)態(tài)組件實(shí)現(xiàn)異常處理方法
Vue3動(dòng)態(tài)組件怎么進(jìn)行異常處理?下面本篇文章帶大家聊聊Vue3 動(dòng)態(tài)組件異常處理的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-02-02vue3.0 CLI - 2.6 - 組件的復(fù)用入門教程
這篇文章主要介紹了 vue3.0 CLI - 2.6 - 組件的復(fù)用,非常不錯(cuò),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2018-09-09Spring Boot/VUE中路由傳遞參數(shù)的實(shí)現(xiàn)代碼
在路由時(shí)傳遞參數(shù),一般有兩種形式,一種是拼接在url地址中,另一種是查詢參數(shù)。這篇文章主要介紹了Spring Boot/VUE中路由傳遞參數(shù),需要的朋友可以參考下2018-03-03vuex中數(shù)據(jù)持久化插件vuex-persistedstate使用詳解
這篇文章主要介紹了vuex中數(shù)據(jù)持久化插件vuex-persistedstate使用詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03