Last active
July 4, 2016 06:10
-
-
Save htfy96/ada384b5db80203f05cc3b40aed1aa2d to your computer and use it in GitHub Desktop.
Amazeui datepicker.vue
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 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