一、defineProps
const props = withDefaults(defineProps<{
msg?: String
}>(),{
msg: 'sss'
})
二、defineEmits
const emit = defineEmits<{
(e: 'xxx1', msg: String): void,
(e: 'xxx2', num: Number): void,
}>()
emit('xxx1', 'jim')
三、defineExpose
使用场景:aui暴露出方法,在父组件中获取子组件实例后,直接调用其方法
子组件中:
defineExpose({
msg,
func
})
父组件中:
<template>
<child ref="son">
</template>
const son = ref()
onMounted(() => {
console.log(son.value.msg)
console.log(son.value.func)
})