Advanced Vue: Controlling Parent Slots (Case Study) Michael Thiessen on August 16, 2019 Let me ask you about something you've probably never thought about: Is there a way to populate a parent's slot from a child component? Recently... Read full post Submit Preview Dismiss Collapse Expand Andrei Gatej Andrei Gatej Andrei Gatej Follow On a never-ending learning journey. Email andreigtj01@gmail.com Location Romania Joined Feb 20, 2018 • Aug 17 '19 Dropdown menu Copy link Hide Interesting problem! I’d use vm.$root.$on and vm.$root.$emit to be able to control a component from outside. <template> <div> <FullPageError /> <component :is=“crtActionBar” /> <App /> </div> </template> <script> export default { data: () => ({ crtActionBarName: ‘action1’, }), computed: { crtActionBar () { return () => import(`path/to/dir/actionBars/${this.crtActionBarName}`) } }, created () { this.$root.$on(‘changeActionBar’, actionBarName => { this.crtActionBarName = actionBarName; }) } } </script> Now from your child component, where you want to change parent’s data from. created () { this.$root.$emit(‘changeActionBar’, ‘action2’); } Code of Conduct • Report abuse
Interesting problem!
I’d use
vm.$root.$onandvm.$root.$emitto be able to control a component from outside.Now from your child component, where you want to change parent’s data from.