How to access to a child method from the parent in vue.js

前端 未结 4 1960
深忆病人
深忆病人 2020-11-30 00:33

I have two nested components, what is the proper way to access to the child methods from the parent ?

this.$children[0].myMethod() seems to do the trick

4条回答
  •  醉酒成梦
    2020-11-30 00:38

    To communicate a child component with another child component I've made a method in parent which calls a method in a child with:

    this.$refs.childMethod()
    

    And from the another child I've called the root method:

    this.$root.theRootMethod()
    

    It worked for me.

提交回复
热议问题