Vue 3 中使用defineEmits

在 Vue 3 中,defineEmits 用于在组件中定义自定义事件,使得子组件可以向父组件发送数据。以下是 defineEmits 的基本用法

  • 子组件 ChildComponent.vue

  • 父组件




ts 中使用

  • 子组件
  
  • 父组件
interface Emits {
  (e: "update:code", code: string): void;
}

const emit = defineEmits();

watch(imgCode, newValue => {
  emit("update:code", newValue);
});

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