[Vuejs]-Binding no-ops or null handlers to Vue event handlers?

0👍

I don’t think there is much of a noticeable difference unless you benchmark it.

If this matters to you, you could choose to not have the appear handler by passing a dynamic object to v-on instead.

<transition ... v-on="transitionEventHandlers">

JS

  data: {
    shouldUseAppearHandler: true
  },
  computed: {
    transitionEventHandlers() {
      let handlers = {
        enter: this.doEnter
      };
      if(this.shouldUseAppearHandler) {
        handlers = {
          appear: this.doAppear,
          ...handlers
        }
      }
      return handlers;
    }
  },
  methods: {
    doEnter() {
      console.log("enter");
    },
    doAppear() {
      console.log("appear");
    }
  }

example: https://codepen.io/jacobgoh101/pen/aGVzjR?editors=1011

Leave a comment