Skip to content

Instantly share code, notes, and snippets.

@leaysgur
Created March 16, 2014 11:26
Show Gist options
  • Save leaysgur/9581838 to your computer and use it in GitHub Desktop.
Save leaysgur/9581838 to your computer and use it in GitHub Desktop.
Use Vue.js and v-tap directicve with jQuery.tap.js
<div id="sample">
<div class="hoge" v-tap="hoge"></div>
</div>
<script src="path/to/vue.js"></script>
<script src="path/to/vue.tap.js"></script>
<script src="path/to/jquery.js"></script>
<script src="path/to/jquery.tap.js"></script>
<script>
var vue = new Vue({
el: '#sample',
methods: {
hoge: function() { console.log('Tap!'); }
}
});
</script>
Vue.directive('tap', {
isFn: true,
bind: function () {
this.el = $(this.el);
},
update: function (fn) {
var vm = this.vm;
this.handler = function (e) {
e.targetVM = vm;
fn.call(vm, e);
}
this.el.on('tap', this.handler);
},
unbind: function () {
this.el.off('tap');
this.el = null
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment