Blogger Information
Blog 47
fans 0
comment 2
visits 102523
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
vue 向上通知、向下广播(子传父,父传子)
拾一枝樱花的博客
Original
1088 people have browsed it

1.向上通知

Vue.prototype.$dispatch = (eventName, value) => {

    let parent = this.$parent

    while(parent){

        parent.$emit(eventName, value)

        parent = parent.$parent

    }

}

2.向下广播

Vue.prototype.$boardcast = (eventName, value) => {

    const boardcast = (children) => {

        children.foreach(child =>{

            child.$emit(eventName, value)

            if(child.$children) {

                boardcast (child.$children)

            }

        })

    }

    boardcast(this.$children)

}

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post