Last active
May 21, 2021 02:53
-
-
Save MrDave1999/95bae18488fb853512cc33ac9bf38205 to your computer and use it in GitHub Desktop.
(VueJS) Componente input-datetime personalizado
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> | |
<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