The basic concept
- The event listens to addEventListener
Listen for an event to fire and perform a callback.
- CustomEvent CustomEvent
Initialize a CustomEvent object. If the initialization is repeated, it will be overwritten.
- Event dispatchEvent
In plain English, events are triggered directly in JS.
Method of use
Go straight to the example:
Dom.addeventlistener ("cat", function(e) {console.log(e.dial)}); // create a CustomEvent let event = new CustomEvent("cat", {bubbles:true, // Whether bubble cancelable:true,// whether cancelable event is supported detail:{say:'hello world'}}); Dom.dispatchevent (event); //{say:'hello world'}Copy the code
By the way, for other content, check out more of my articles at 😋