one
Using the one method, you can register a one-time event handler for the target element, which means the event handler will automatically unbind after the first trigger and will not be triggered again.
Below is an example showing how to use the one method to register a click event handler for a button element:
-
In this example, we use the one method to add a click event handler to the button element. When the user clicks the button, the event handler is triggered, but it will not be triggered again because it has been unbound.
Using Template Syntax
You can also use template syntax to bind a one-time event handler to the target element.
{{count}}
In this example, we use one:click on a button element to bind a method named addCount. When the user clicks the button, this method will be called, but it will not be triggered again because it is a one-time event handler.