Vue3+TS 父子组件传参

54 阅读1分钟
// 子传父
const emit = defineEmits(['getVerificationCode'])
// 接收父组件的值 TS特有写法
type Props = {
    width?: string,
    height?: string,
    length?: number,
}
const props = withDefaults(defineProps<Props>(), {
    width: '80px',
    height: '34px',
    length: 4,
})
emit('getVerificationCode', state.codeList.map(item => item.code).join(''))
// 接收子组件(验证码)传的值
const getVerificationCode = (codeList: string) => {
    state.ruleForm.verificationCode = codeList;
};