[Vuejs]-Call child method from parent without ref in VUE3

0๐Ÿ‘

I also encountered this problem just now, my solution is to get the subcomponent directly

<grid-item
          ref="gridItemRef"
          v-for="item in layoutData"
          :x="item.x"
          :y="item.y"
          :w="item.w"
          :h="item.h"
          :i="item.i"
          :key="item.i"
          @resized="resizeEvent"
        >
          {{ item.i }}
        </grid-item>

gridItemRef.value[layoutData.value.length].$el.style.display = "none";
const el = gridItemRef.value[index];
el.calcXY(
      mouseXY.y - parentRect.top,
      mouseXY.x - parentRect.left
    );

Leave a comment