Skip to content

Is there any opportunities to share own methods in a custom directive around bind/unbind/update? #314

@Jinjiang

Description

@Jinjiang

For example, I would add a event listener when bind and remove it when unbind. So I wrote:

Vue.directive('xxx', {
  bind: function () {
    this.vm.handler = function () {...};
    this.el.addEventListener('click', this.vm.handler);
  },
  unbind: function () {
    this.el.removeEventListener('click', this.vm.handler);
    delete this.vm.handler;
  }
});

But the handler is exposed out to vm.
Is there any better way?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions