📌  相关文章
📜  vuejs触发函数中的一个组件到另一个组件 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:01:50.835000             🧑  作者: Mango

代码示例1
For 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.

On First component

    ....
    mounted() {
        this.$root.$on('component1', () => {
            // your code goes here
            this.c1method()
        }
    }
                       
and in the second component call the $emit function in $root

    ...
    c2method: function(){
     this.$root.$emit('component1') //like this
    },
It acts more like a socket. Reference here

https://stackoverflow.com/a/50343039/6090215