likes
comments
collection
share

Vue3 declare it using the "emits" option警告

作者站长头像
站长
· 阅读数 970

Vue3已将父子组件传值修改为defineEmits函数,但是在日常使用时有时会报错:[Vue warn]: Extraneous non-emits event listeners (update) were passed to component but could not be automatically inherited because component renders fragment or text root nodes. If the listener is intended to be a component custom event listener only, declare it using the "emits" option.

Vue3 declare it using the "emits" option警告

通过警告信息可以得出Vue需要我们将emits中的传参事件标明:

<script setup>
import { ref, watchEffect, watch, computed } from "vue";
let emit = defineEmits(["update:mode", "update:data", "update"]);
let props = defineProps({
  mode: {
    type: [String, Boolean],
    required: true,
  },
  data: {
    type: Object,
    required: true,
  },
});
</script>

这样修改,将需要用到的事件在定义时传在函数就可以了