forked from dmuy/duDatepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-datepicker.js
63 lines (57 loc) · 2.1 KB
/
vue-datepicker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import './dist/duDatepicker.css'
import duDatepicker from './dist/duDatepicker.js'
export default {
install(Vue, options) {
if (! options) options = {}
// <du-datepicker /> component
Vue.component('duDatepicker', {
render(createElement) {
return createElement('input', {
domProps: {
type: 'text'
},
on: {
datechanged: e => {
this.$emit('datechanged', e)
}
}
})
},
props: {
options: { type: Object },
ready: { type: Function },
dateChanged: { type: Function },
onRangeFormat: { type: Function },
shown: { type: Function },
hidden: { type: Function }
},
methods: {
setValue(value) { duDatepicker(this.$el, 'setValue', value) },
show() { duDatepicker(this.$el, 'show') },
hide() { duDatepicker(this.$el, 'hide') },
destroy() { duDatepicker(this.$el, 'destroy') }
},
mounted() {
let evtProps = {
events: { ready: this.ready, dateChanged: this.dateChanged, onRangeFormat: this.onRangeFormat, shown: this.shown, hidden: this.hidden }
}
// remove undefined callbacks
Object.keys(evtProps.events).forEach(key => evtProps.events[key] === undefined && delete evtProps.events[key])
// initialize
duDatepicker(this.$el, { ...options, ...this.options, ...evtProps })
},
destroyed() {
this.destroy()
}
})
// v-du-datepicker directive
Vue.directive('du-datepicker', {
bind(el, binding) {
duDatepicker(el, { ...options, ...binding.value })
},
unbind(el) {
duDatepicker(el, 'destroy')
}
})
}
}