[Vuejs]-Add a inline function with args in custom function directive

0๐Ÿ‘

โœ…

I hope I understood you correctly, but this is probably some boilerplate of what you want:

Vue.directive('demo', function (el, binding) {
  // Add any event listener here that you want
  el.addEventListener('touchstart', () => {
    // Execute the function bound to the directive
    binding.value()
  })
})

const app = new Vue({
  el: '#app',
})

And the template:

<div id="app">
  <h1 v-demo="() => {alert('hello')}">Click me for alert</h1>
</div>

Or in your case:

<custom-element v-demo="() => {this.$emit('change', 'test', true)}" />
๐Ÿ‘คPhilip Feldmann

Leave a comment