- 父组件调用子组件使用
defineExpose
暴露的属性和方法时,需要先用ref
获得子组件实例,再通过子组件实例调用 - 如果子组件是用
router-view
渲染的话,就无法直接通过ref
获取到子组件的实例了,那么可以用如下方法获得子组件实例
<router-view v-slot="{ Component }">
<component :is="Component" ref="child" />
</router-view>
defineExpose
暴露的属性和方法时,需要先用ref
获得子组件实例,再通过子组件实例调用router-view
渲染的话,就无法直接通过ref
获取到子组件的实例了,那么可以用如下方法获得子组件实例<router-view v-slot="{ Component }">
<component :is="Component" ref="child" />
</router-view>