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之外:文章来源:https://www.toymoban.com/news/detail-706849.html
export default {
//提前声明你要使用的自定义事件
emits: ['modelValue'],
......
mounted(){
this.$emit('modelValue','hello world')
},
setup(){
......
}
}
第二种,setup之内:文章来源地址https://www.toymoban.com/news/detail-706849.html
<script setup>
//提前声明你要使用的自定义事件
const emit = defineEmits(['modelValue'])
emit('modelValue', 'hello world')
</script>
到了这里,关于vue3警告Extraneous non-emits event listeners (XXX) were passed to component but could not be automatic的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!