Access $refs from other components not in the same level as current component

后端 未结 3 1842
温柔的废话
温柔的废话 2021-01-04 07:05

I\'m working on a Vue application. It has a header and then the main content. Nesting and structure as below

TheHeader.vue -> TheLogin.vue

MainContent.vu         


        
3条回答
  •  日久生厌
    2021-01-04 07:58

    For anyone who comes here later and wants to access $refs in parent component, not in this particular case for emitting events since event bus or a store would suffice but let's just say you want to access some element in parent to get it's attributes like clientHeight, classList etc. then you could access them like:

    this.$parent.$parent.$refs //you can traverse through multiple levels like this to access $ref property at the required level
    

提交回复
热议问题