javascript - VueJS Custom Directive Function as Argument -


i've got simple directive:

html:

<div id="app">   <div v-sample:callback="greet"></div> </div> <script>   var app = new vue({     el: "#app",     data: {       files: [],     },     methods: {       greet: function (arg) {         alert(arg);       },     },   }); </script> 

js:

vue.directive('sample', {   bind: function (el, binding, vnode) {     el.addeventlistener('...', function () {       // ...       callback.call(arg, ...);     });   }, }); 

however, i'm unclear of appropriate syntax function , evaluate. what's proper way within directive?

you can use binding.value should function in case. it's prebound correct context call (pass in if need something):

vue.directive('sample', {   bind: function (el, binding, vnode) {     el.addeventlistener('click', function () {       binding.value()     });   }, }); 

Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -