一。子组件访问父组件的方法
< DialogEditing @close- dialog= "handleClose" / >
const handleClose = ( ) => { } ;
const emit = defineEmits ( [ "closeDialog" ] ) ;
const close = ( ) => { emit ( "closeDialog" ) ;
} ;
二。父组件访问子组件的属性或方法
< script setup>
const count = ref ( 0 ) ;
const increment = ( ) => {
}
defineExpose ( { count, increment,
} ) ;
< / script>
< Child ref= "childRef" / > const childRef = ref ( null ) ;
const accessChild = ( ) => { childRef. value. increment ( ) ; console. log ( 'Current count:' , childRef. value. count) ;
}
< / script>
三。子组件修改父组件的值
< ImportFile ref= "fileDialogRef" v- model: lead- visible= "leadVisible" / > const leadVisible = ref ( false ) ;
const props = defineProps ( { leadVisible : { type : Boolean }
} ) ;
let { leadVisible } = toRefs ( props) ;
const emit = defineEmits ( [ "update:leadVisible" ] ) ; const handleFile = ( ) => { emit ( "update:leadVisible" , true ) ;
} ;