Created
November 24, 2020 08:58
-
-
Save Shagshag/a8138286ef5011d2ce6636ec03afcfce to your computer and use it in GitHub Desktop.
input-date for vue3
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
// adapted from https://acdcjunior.github.io/how-bind-date-object-to-input-date-vue.js-v-model.html | |
{ | |
props: ['modelValue'], | |
emits: ['update:modelValue'], | |
setup() { | |
const dateToYYYYMMDD = (d) => { | |
// alternative implementations in https://stackoverflow.com/q/23593052/1850609 | |
try { | |
return d && new Date(d.getTime()-(d.getTimezoneOffset()*60*1000)).toISOString().split('T')[0]; | |
} catch(e) { | |
return null; | |
} | |
}; | |
return { | |
dateToYYYYMMDD, | |
} | |
}, | |
template: ` | |
<input | |
v-model="value" | |
type="date" | |
@input="$emit('update:modelValue', $event.target.valueAsDate)" | |
/> | |
`, | |
computed: { | |
value: { | |
get() { | |
return this.dateToYYYYMMDD(this.modelValue); | |
}, | |
set(value) { | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment