The understanding of $emit in Vue.js

Source: Internet
Author: User
Tags emit

Website Introduction is relatively simple

Example: $emit (' increment1 ', [KKK ']), directly see if there is no, can tell you, is to trigger a custom event Increment1 (or function name bar), [] parameter

On the case

<! DOCTYPE html>"UTF-8"> <title></title> "Counter-event-example"> <p>{{Total}}</p> <button-counter v-on:increment1="Incrementtotal"></button-counter> <button-counter v-on:increment2="Incrementtotal"></button-counter> </div> </body> <script src="Vue/vue.min.js"></script> <script>Vue.component ('Button-counter', {Template:'<button v-on:click= "increment" >{{counter}}</button>', Data:function () {return{counter:0}//Component data that's the way it is, functional, please note}, methods:{increment:function () { This. Counter + =1;  This. $emit ('Increment1',[ A,'KKK']);//$emit                }            }        }); NewVue ({el:'#counter-event-example', data:{total:0}, methods:{incrementtotal:function (e) { This. Total + =1;                Console.log (e);    }            }        }); </script>

See Component Button-counter First

The event click is bound ———— >increment

Then this.counter + = 1; this. $emit (' increment1 ', [KKK ']);

This is the trigger event increment1, the reference is a bit messy, this side is not much clearer

Then <button-counter v-on:increment1= "Incrementtotal" ></button-counter>

V-on is the equivalent of listening, triggering incrementtotal.

Output//["KKK"]

There is no clear, if there is no understanding of the place, please correct me

Reference: HTTP://ARINU.ME/?P=50

The understanding of $emit in Vue.js

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.