Vue3子组件传参给父组件(变量传参)

子组件代码

const emit = defineEmits(['identifyCodeValue']) // 定义自定义事件
const changeCanvasVal = () => {
  state.identifyCode = draw();
  emit('identifyCodeValue', state.identifyCode) // 触发自定义事件并传递state.identifyCode值
};

父组件接收

 

// 引入组件
const AccountCanvas = defineAsyncComponent(() => import('/@/views/login/component/accountCanvas.vue'));

// 定义变量接受子组件参数值
const stateValue = reactive({
	identifyCode: "",
});

// 将传递过来的验证码保存到父组件的数据项中
const identifyCodeValue = (identifyCode: string) => {
	stateValue.identifyCode = identifyCode
};

你可能感兴趣的:(前端,javascript,vue.js)