Possible to open modal from outside the vue component

前端 未结 5 512
别跟我提以往
别跟我提以往 2021-01-03 06:31

Is it possible to call a method from outside the component to make the component reuseable?

Right now I add my button to open the modal in a template slot:

<

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-03 06:52

    There is no (easy, supported) way to call a method in a component, but you can either modify a property in the child (eg. show) (see Passing Data to Child Components with Props) or use events (see Custom Events, $emit and $refs). Using events you could also use an event bus. The event based solution is of course better suited to more complex interactions.

提交回复
热议问题