Whenever the eats method in the Cat component is called, it emits an onHappy event. ![]() Instead, Vue.js has a custom events system that accomplishes the same thing: # Parent As the application grows larger in size and other developers come on board, they will look at the child component code and have to figure out which callback function prop it is and where it is from. Every time execute runs, it needs to check for and execute the callback function passed down.Īs you reuse this child component, you start having different callback functions passed down from different parents. In the example above, the child now needs to know about the context of the function prop from its parent. By passing functions down as props, you are linking both parent child components together with two-way data binding. While this would work perfectly, this is mostly considered an anti-pattern in Vue. This is also doable in Vue.js using code like this: Īnd in the child component, you receive the function as a prop: ![]() The function call then flows back up from the child to the parent, faciliating parent-child component communication. In React you can pass down functions as props from the parent to the child component.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |