方法一,直接获取

// 子组件 抛出方法
defineExpose({ init });

 

// 父组件
// 1.引入子组件
import addMinorJnjuries from "../dialog/minorJnjuriesDialog/addMinorJnjuries.vue";
      <addMinorJnjuries
        ref="addRef"
        :dialogVisible="showDialog"
        @close="closeDialog"
        @getDataList="getDataList"
      ></addMinorJnjuries>
      
// 2.获取子组件ref实例
const addRef = ref<InstanceType<typeof addMinorJnjuries>>();
// 3.使用
if (addRef.value) addRef.value.init(row.id, "编辑");

// 注意   不加if判断会有警告 !!!

方法二 在父组件实例中获取

getCurrentInstance

import { getCurrentInstance } from "vue";

const { proxy } = <any>getCurrentInstance();

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐