Skip to content

Instantly share code, notes, and snippets.

@cn-2k
Created March 18, 2022 16:46
Show Gist options
  • Save cn-2k/2e032f74c49d935b0d987f582f186943 to your computer and use it in GitHub Desktop.
Save cn-2k/2e032f74c49d935b0d987f582f186943 to your computer and use it in GitHub Desktop.
el-date-picker component (Element UI)
<template>
// Component attrs
<el-date-picker
:size="props.size"
:modelValue="props.modelValue"
@change="onChange"
@update:modelValue="handleUpdate($event, value)"
:type="props.type"
range-separator="-"
start-placeholder="Data inicial"
end-placeholder="Data final"
format="DD/MM/YYYY"
value-format="YYYY-MM-DD"
:disabled="props.disabled"
/>
</template>
<script setup>
// Component props using defineProps from script setup
const props = defineProps({
size: {
type: String,
required: true,
},
modelValue: {
type: [String, Number, Array, Object],
default: Array,
},
type: {
type: String,
required: true,
},
disabled: {
type: Boolean,
},
})
// Component emits using defineEmits from script setup
const emit = defineEmits(['update:modelValue', 'onChange'])
// this will exec an method attached to @change event on parent component
const onChange = (value) => {
emit('onChange', value)
}
// this will update model value in parent component
const handleUpdate = (value) => {
emit('update:modelValue', value)
}
</script>
<style scoped>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment