Skip to content

Instantly share code, notes, and snippets.

@htfy96
Last active July 4, 2016 06:10
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 htfy96/ada384b5db80203f05cc3b40aed1aa2d to your computer and use it in GitHub Desktop.
Save htfy96/ada384b5db80203f05cc3b40aed1aa2d to your computer and use it in GitHub Desktop.
Amazeui datepicker.vue
<template id="datepicker-template">
<div class="am-input-group am-datepicker-date" data-am-datepicker="{format: 'yyyy-mm-dd'}" v-dp="date">
<input type="text" class="am-form-field" readonly >
<span class="am-input-group-btn am-datepicker-add-on">
<button class="am-btn am-btn-default" type="button"><span class="am-icon-calendar"></span> </button>
</span>
</div>
</template>
<script>
Vue.directive('dp', {
bind: function () {
var vm = this.vm;
var key = this.expression;
var el = this.el;
$(this.el).datepicker().on('changeDate.datepicker.amui', function (event) {
vm.$set(key, $(el).data('date'));
$(this).datepicker('close');
});
},
update: function(newv, oldv) {
$(this.el).datepicker('setValue', newv);
}
});
Vue.component('datepicker', {
template: '#datepicker-template',
props: ['date']
});
</script>
<!-- Usage: -->
<div id="container">
<datepicker :date.sync="date" />
Current date: {{date}}
</div>
<script>
new Vue({
el: '#container',
data: {
date: '2011-02-03'
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment