vue3 警告Extraneous non-emits event listeners (selectMeth) 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.

之所以出现这个警告,是因为在子组件向父组件发送自定义事件的时候,没有使用“emits”选项声明它。

这里使用两种方式改正 emits 选项。

第一种,setup之外:

export default {
  //提前声明你要使用的自定义事件
  emits: ['modelValue'],
  ......
  mounted(){
	this.$emit('modelValue','hello world')
  },
  setup(){
  	......
  }
}

第二种,setup之内:

<script setup>
    //提前声明你要使用的自定义事件
	const emit = defineEmits(['modelValue'])
	emit('modelValue', 'hello world')
</script>
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐