Home  >  Q&A  >  body text

javascript - How to pass events out of a tree component written recursively in VUE?

Due to recursive components, this kind of nesting will occur

<tree>
    <tree>
        <tree>

        </tree>
    </tree>
</tree>

It’s easy to select the outermost one. Dynamically register a Vuex module. Whichever one is clicked will be passed to this module.

But it is troublesome to implement click and $emit events in the tree structure. They are nested layer by layer and it is almost impossible to broadcast

Please tell me how to solve this problem

漂亮男人漂亮男人2641 days ago805

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-06-30 10:01:45

    You can use $on and $emit:

    Custom events

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-06-30 10:01:45

    The officially recommended approach is to use a Vue instance as the event bus.

    reply
    0
  • Cancelreply