Skip to main content

二次封装子组件暴露

二次封装组件如何暴漏子组件的方法

https://www.bilibili.com/video/BV1EJstecEbA/?spm_id_from=333.1007.tianma.1-1-1.click&vd_source=412c43a0ceeaa0496e47ada8a74ac2ef

<template>
<el-input ref="inputRef"> </el-input>
<template>

<scripts setup lang="ts">
const inputRef = ref()

// 这里使用代理对象进行导出

defineExpose(
new Proxy(
{},
{
get(target, key){return inputRef.value?.[key]},
has(target, key){return key in inputRef.value} // 这里的has是必须的,否则会失效
}
)
)
</scripts>

二次封装动态插槽

image-20240912150346261