one component to another component in vuejs trigger function

Solutions on MaxInterview for one component to another component in vuejs trigger function by the best coders in the world

showing results for - "one component to another component in vuejs trigger function"
Arianna
03 Oct 2020
1For non-parent-child relation, then this is the same as this one. Call one method, apparently any method of a component from any other component. Just add a $on function to the $root instance and call form any other component accessing the $root and calling $emit function.
2
3On First component
4
5    ....
6    mounted() {
7        this.$root.$on('component1', () => {
8            // your code goes here
9            this.c1method()
10        }
11    }
12                       
13and in the second component call the $emit function in $root
14
15    ...
16    c2method: function(){
17     this.$root.$emit('component1') //like this
18    },
19It acts more like a socket. Reference here
20
21https://stackoverflow.com/a/50343039/6090215