包装第三方组件时,可以使用“v-bind=$attrs”自动传递props和emits。 childComponent 的暴露如何像他们一样自动传递?
// ChildComp
<script setup lang="ts">
import { PropType } from 'vue';
defineProps({
name:String,
list:Array as PropType<any[]>,
})
defineEmits(['change', 'delete'])
defineExpose({
method1:()=>{
//...
},
method2:()=>{
//...
},
method3:()=>{
//...
},
method4:()=>{
//...
},
...
})
</script>
// MyComp
<template>
<--! others -->
<ChildComp v-bind="$attrs"/>
</template>
<script setup lang="ts">
import ChildComp from './ChildComp.vue'
defineExpose({
myMethod:()=>{ //... }
})
// method1,method2,method3,method4... of ChildComp
// How to expose all?
</script>
自动暴露子组件传递