建立,seo顾问服务咨询,2024年还会封城吗,淘宝网页版电脑版登录当父组件调用子组件的script setup中的方法时#xff0c;必须显式导出该方法。因为 script setup 中定义的变量和方法默认是局部的#xff0c;只有显式导出后#xff0c;父组件才能访问这些方法。
//父组件-Parent
templateel-button typeprimary …当父组件调用子组件的script setup中的方法时必须显式导出该方法。因为 script setup 中定义的变量和方法默认是局部的只有显式导出后父组件才能访问这些方法。
//父组件-Parent
templateel-button typeprimary clickaddOrUpdateHandle(){{ $i18(add) }}/el-button!-- 弹窗, 新增 / 修改 --add-or-update refaddOrUpdateRef/add-or-update
/template
script setup
import { unref } from vue;
const addOrUpdateHandle (row) {const instance unref(addOrUpdateRef);if (instance typeof instance.init function) {instance.init(row);}
};
/script//子组件-Child
templateel-dialogv-modelvisible/el-dialog
/template
script setup
import { reactive } from vue;
const state reactive({visible: false,
});
const init () {state.visible true;
};
// 使用 defineExpose 导出 init 方法
defineExpose({init,
});
/script