Created
May 5, 2022 20:29
-
-
Save cn-2k/f12da5c27aeeeafcf979c2d0cd41ce0f to your computer and use it in GitHub Desktop.
My Element UI Date Picker Range in Vue 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<Calendar | |
size="mini" | |
v-model="myDate" | |
:type="dataExibitionTime === 'monthly' ? 'monthrange' : dataExibitionTime === 'yearly' ? 'monthrange' : 'daterange'" | |
@change="setRangeDate(); someFunction(param)" | |
/> | |
</div> | |
</template> | |
<script setup> | |
import dayjs from 'dayjs' | |
// Here I work with el-date-picker as component | |
import Calendar from '@/components/Calendar.vue' | |
const dataExibitionTime = ref('daily') | |
const myDate = ref([calendarRange.value.start, calendarRange.value.end]) | |
// Object with my start and end date (using dayjs to get a full month) and formatting date | |
const calendarRange = ref({ | |
start: dayjs().startOf('month').format('YYYY-MM-DD'), | |
end: dayjs().endOf('month').format('YYYY-MM-DD'), | |
}) | |
// Here I set an start and end date to my v-model (myDate) | |
const setRangeDate = () => { | |
calendarRange.value.start = myDate.value[0] | |
calendarRange.value.end = myDate.value[1] | |
} | |
</script> | |
<style lang="css" scoped> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment