Pass Data From Child To Parent Vuejs4/21/2021
If you have defined your root component as following new Vue(.Custom Events This is most natural of passing state changes back to parent component as we all know vue has adapted one way data flow and for good reasons so in everyday routine you will refactor your components based on single responsibility principle you break the orignal components to various child components.Now they need data you pass the data to them using props but remember we are in realm of one way data flow so suppose now user has interacted with that child component and now you need to communicate that change back to parent what would you do answer is custom events.Lets say we have structured our todo app like this after refactoring.
Pass Data From Child To Parent Vuejs Update Event AndNow back in parent component we can listen to the update event and get the updated todo item as well. As we are currently covering passing data back to parent components its important to mention that within event bus you can listen to state changes within any part of your frontend application whether the component is directly up in hierarchy or it its further down by using eventbus it doesnt matter. Usually this technique is used to propagate changes to unrelated components within your app. Now in order to generate events and send them to event bus you will have to import EventBus and use emit method to do so, this is explained in detail in the following example. Admin Carbonteq Web Development Search Latest Posts The Future of Cloud Computing: SaaS, PaaS, and IaaS 19 August, 2020 Embracing Agile: What is Agile Methodology and How to implement it effectively 18 June, 2020 Command Bus Pattern 21 April, 2020 Introduction to Pakistans first email service 14 April, 2020 Custom Exception Handling. Browse through our blog for help with setting up different environments for programming. All Rights Reserved.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |