Skip to content

Instantly share code, notes, and snippets.

@MrDave1999
Last active May 21, 2021 02:53
Show Gist options
  • Save MrDave1999/95bae18488fb853512cc33ac9bf38205 to your computer and use it in GitHub Desktop.
Save MrDave1999/95bae18488fb853512cc33ac9bf38205 to your computer and use it in GitHub Desktop.
(VueJS) Componente input-datetime personalizado
<template>
<input type="datetime-local" v-bind:value="decode" v-on:input="encode" />
</template>
<script>
export default {
name: 'DateTime',
props:{
value: String
},
computed:{
decode(){
return this.value.replace(' ', 'T');
}
},
methods:{
encode(event){
this.$emit('input', event.target.value.replace('T', ' '));
}
}
}
/*
-> Ejemplo:
Puedes usar el componente personalizado de esta forma:
<DateTime v-bind:value="fecha_hora" v-on:input="fecha_hora = $event" />
Que vendría ser equivalente a:
<DateTime v-model="fecha_hora" />
*/
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment