Home  >  Article  >  Web Front-end  >  What are the uses of $emit in vue?

What are the uses of $emit in vue?

php中世界最好的语言
php中世界最好的语言Original
2018-04-28 14:23:354907browse

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: