one
Using the one method, you can register a one-time event handler for a target element, meaning the handler will automatically unbind after the first trigger and will not fire again.
Below is an example demonstrating 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 triggers but will not fire again afterward because it has been unbound.
Template Syntax Usage
You can also use template syntax to bind a one-time event handler to the target element.
{{count}}
In this example, we bind a method named addCount to the button element using one:click. When the user clicks the button, this method will be called, but it will not trigger again afterward because it is a one-time event handler.