Skip to content

Instantly share code, notes, and snippets.

@Shagshag
Created November 24, 2020 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shagshag/a8138286ef5011d2ce6636ec03afcfce to your computer and use it in GitHub Desktop.
Save Shagshag/a8138286ef5011d2ce6636ec03afcfce to your computer and use it in GitHub Desktop.
input-date for vue3
// 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