Home > Article > Web Front-end > What are the uses of $emit in vue?
This time I will show you how to use $emit in vue, and what notesare when using $emit in vue. The following is a practical case, let's take a look.
1. Parent components can use props to pass data to child components.
2. Subcomponents can use $emit to trigger custom events of parent components.
vm.$emit( event, arg ) //触发当前实例上的事件 vm.$on( event, fn );//监听event事件后运行 fn;
For example: Child component:
大连
Parent component:
//监听子组件的showCityName事件。
The result is:
toCity: Dalian
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
jQuery implements mouse click suspension effect
JS implements text font printing interface
The above is the detailed content of What are the uses of $emit in vue?. For more information, please follow other related articles on the PHP Chinese website!