vue3警告Extraneous non-emits event listeners (XXX) were passed to component but could not be automatic
之所以出现这个警告,是因为在子组件向父组件发送自定义事件的时候,没有使用“emits”选项声明它。这里使用两种方式改正emits选项。
·
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>
更多推荐
已为社区贡献5条内容
所有评论(0)