vue3 的 emits 是什么
在使用 vue3 的时候出来一堆警告的东西,一直没在乎它,今天看了下,原来是 vue3 对比 vue2 新增的特性
警告提示:
runtime-core.esm-bundler.js?5c40:38 [Vue warn]: Extraneous non-emits event listeners (delete) 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.
at <ResultList resultList= [] onDelete=fn<bound deleteResultAt> >
at <App>
意思就是说组件中如果使用了
$emit
向父组件传递事件,就需要在
emits
字段中记录这个事件名
比如:
我在子组件中使用了
<button @click="$emit('delete')">删除</button>
export default {
props: {
},
emits: ['delete'],
mounted(){}
}