登录/注册

Vue3 declare it using the "emits" option警告

用户头像管理员459阅读

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.

填坑,Vue

通过警告信息可以得出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>

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

Preview
登录后评论