Created
July 7, 2018 14:55
-
-
Save paltman/2ac20b227a9d5069bba4b33038dd539d to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
<div class="date-time-picker"> | |
<datepicker v-model="date" :inline="true" /> | |
<vue-timepicker v-model="time" format="hh:mm A" :minute-interval="15" /> | |
</div> | |
</template> | |
<script> | |
import VueTimepicker from 'vue2-timepicker'; | |
import Datepicker from 'vuejs-datepicker'; | |
export default { | |
name: 'date-time-picker', | |
data: () => { | |
return { | |
date: new Date(), | |
time: { | |
hh: '08', | |
mm: '00', | |
A: 'AM' | |
} | |
} | |
}, | |
components: { | |
Datepicker, | |
VueTimepicker | |
}, | |
props: { | |
value: Date | |
}, | |
methods: { | |
emitDate() { | |
const timeString = `${this.time.hh}:${this.time.mm} ${this.time.A}`; | |
const dateString = this.date.toDateString(); | |
this.$emit('input', new Date(`${dateString} ${timeString}`)); | |
} | |
}, | |
watch: { | |
date() { this.emitDate() }, | |
time() { this.emitDate() } | |
} | |
} | |
</script> |
This file contains hidden or 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> | |
<date-time-picker v-model="date" /> | |
</template> | |
<script> | |
import DateTimePicker from './DateTimePicker.vue'; | |
export default { | |
name: 'some-other-component', | |
data: () => { | |
return { | |
date: new Date() | |
} | |
}, | |
components: { | |
DateTimePicker | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment