VUE component’s custom event function diagram

Using V-ON Bind Custom Event

(1) WebPack-based project initialization

Before use, we first use NPM to build an Vue application. Make the project well with the WebPack module package, the command is as follows

Under custom empty folder VuePro, MyApp project initialization needs to utilize WebPack to generate a standard directory project folder

Vue Init Webpack MyApp
   
The following will have the following places that let us operate, the first few direct press Enter, then enter n, as shown below

After the installation is complete, some files and folders are automatically generated under the MYAPP folder, indicating that our project initialization is completed, and Our App.vu is the primary component, and the Components component is a mechanism for the Vue’s code multiplex. Components mix JS and HTML together, as the basis of the entire Vue application layer

Vue组件之自定义事件的功能图解

We can run our project according to the command prompted by the terminal

CD myApp Vue组件之自定义事件的功能图解

NPM Run DEV

   We will assign the URL obtained in the above to the browser to open. Get the following page indicates that our WebPack-based project is successful 

Vue组件之自定义事件的功能图解 Open the main component, if the pro appears like the following reminder, because our JavaScript does not support ES6 syntax, we only need to enter the settings to change the language type.

Vue组件之自定义事件的功能图解 here we canTo introduce the use of component custom events

(2) V-ON && $ EMIT Using $ on (EventName) Mercharge Event Use $ EMIT (EventName) Triggering Event

Vue组件之自定义事件的功能图解

We have built a component Emit.Vue under MyApp / Src / Components, and we have to introduce this component in the primary component app.vue, and register the component

Vue组件之自定义事件的功能图解

Then we go to an example of a custom event in an emit.vue file

When we click on the button, you can get the event box parameters inside the component

Vue组件之自定义事件的功能图解

Summary

The above is the functional diagram of the custom event of the VUE component introduced to you, I hope to help everyone. If you have any questions, please leave a message, the small package will reply to everyone in time. Thank you very much for your support of Tumi Cloud Website! Vue组件之自定义事件的功能图解

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment