Two methods to remove event listeners in Vue: use the v-on directive: first add the listener, and then use the v-on or @ directive to set its value to null to remove it. Use the $off() method: remove the listener directly from the Vue instance, specifying the event name and handler function.
Two methods to remove event listeners in Vue
Method 1: Usev-on
Command
Use thev-on
command to dynamically add or remove event listeners.
To remove a listener, use thev-on
shorthand form@
and set its value tonull
.
Method 2: Use$off()
method
$off()
method can be used from the Vue instance Remove event listener.
this.$off('click', this.handleClick);
Among them,'click'
is the event name,this.handleClick
is the event handling function.
How to choose the removal method
v-on
Instructions are more convenient.$off()
method.The above is the detailed content of EventEmit removes the defined method in vue. For more information, please follow other related articles on the PHP Chinese website!