Created
March 16, 2014 11:26
-
-
Save leaysgur/9581838 to your computer and use it in GitHub Desktop.
Use Vue.js and v-tap directicve with jQuery.tap.js
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
<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> |
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
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