Custom Event function diagrams of Vue components and custom diagrams of vue Components

Source: Internet
Author: User
Tags emit

Custom Event function diagrams of Vue components and custom diagrams of vue Components

Use v-on to bind custom events

(1) webpack-based project Initialization

Before using it, we first use npm to build a vue application so that the project can be used with the webpack module package. The command is as follows:

Enter the custom empty folder vuepro. During myapp project initialization, you must use webpack to generate a standard directory project folder.

vue init webpack myapp

During the installation process, we will see the following operations. The first few will press enter and enter n, as shown in figure

After the installation is complete, some files and folders will be automatically generated under the myapp folder, indicating that our project Initialization is complete, and our APP. vu is the main component, and components is a code reuse mechanism of Vue. components combines js and HTML as the basis of the entire Vue application layer.

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

Cd myapp

npm run dev

Then, assign the obtained URL to the browser. The following page indicates that the webpack-based project has been successfully built.

Open the main component. If you have the same reminder as me, because our javascript does not support ES6 syntax, you only need to change the language type in settings.

Here we can introduce the use of component custom events.

(2) v-on & $ emit uses $ on (eventName) to listen to events and uses $ emit (eventName) to trigger events

Create a new Emit. vue component under myapp/src/components. At the same time, we must introduce this component into the main component APP. vue and register this component.

Then we will go to the Emit. vue file to provide an example of a custom event.

Click the button to obtain the event Box Parameters in the component.

Summary

The above is a demo of the Vue component's Custom Event function. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.