vue3 +ts defineExpose暴露子组件

//父组件
 <div>
  <Search ref="childForm"/>
 </div>
 <script lang="ts" setup>
 const childForm = ref();
 console.log(childForm.value._form)//{groupType: '123',groupName: '456'}
 console.log(childForm.value.show())//'子组件的方法'
 </script>
//子组件Search
<script lang="ts" setup>
const _form = reactive({
      
      
  groupType: '123',
  groupName: '456',
});
const show =()=>{
      
      
	return '子组件的方法'
}
defineExpose({
      
      
  _form,
});
</script>

猜你喜欢

转载自blog.csdn.net/qq_42859450/article/details/127790188
今日推荐