天天看點

vue3 的 emits 是什麼 runtime-core.esm-bundler.js?5c40:38 [Vue warn]: Extraneous non-emits event listener

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(){}
}      

繼續閱讀