Vue: Vue 2 directive deprecated acceptStatement

Created on 22 Jul 2016  路  2Comments  路  Source: vuejs/vue

How do I deal with inline statements !

<div id="app">
    {{show}}
    <button v-tap="show = true">show</button>
    {{show}}
    <button v-tap="hide()">hide</button>
    {{show}}
</div>
Vue.directive('tap', {
    bind: function (el, binding) {
    }
});
var vm = new Vue({
    el: '#app',
    data: {
        show: false
    },
    methods: {
        hide: function () {
            this.$data.show = false;
        }
    }
});

output html

false
<button>show</button>
true
<button>hide</button>
false

why should we abolish it? that is now how to achieve it?

Most helpful comment

It's no longer recommended to create custom directives that behaves like v-on. Instead, you can dispatch native DOM events in your directive, and then use v-on to listen to them:

Vue.directive('tappable', {
    bind: function (el) {
      // when a tap happens
      var e = document.createEvent('HTMLEvents')
      e.initEvent('tap', true, true)
      el.dispatchEvent(e)
    }
});

In template:

<button v-tappable @tap="hide()">

All 2 comments

Hi @TOP-Caho

thanks for filing this issue.

Unfortunately, I don't really understand what the core of the problem is. What is the expected behaviour?

Can you build a jsfiddle to demonstrate the problem, maybe with 1.0.26 and 2.0.0-beta,2 for comparison?

It's no longer recommended to create custom directives that behaves like v-on. Instead, you can dispatch native DOM events in your directive, and then use v-on to listen to them:

Vue.directive('tappable', {
    bind: function (el) {
      // when a tap happens
      var e = document.createEvent('HTMLEvents')
      e.initEvent('tap', true, true)
      el.dispatchEvent(e)
    }
});

In template:

<button v-tappable @tap="hide()">
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bdedardel picture bdedardel  路  3Comments

aviggngyv picture aviggngyv  路  3Comments

seemsindie picture seemsindie  路  3Comments

wufeng87 picture wufeng87  路  3Comments

loki0609 picture loki0609  路  3Comments