vue3-浏览器告警解决: Extraneous non-emits event listeners (queryList, closeDialog) were passed to

最近用vue3编写,经常功能可以实现但是浏览器一大堆警告,强迫症看着实在太难受了。。。

其中一个warn是:

[Vue warn]: Extraneous non-emits event listeners (queryList, closeDialog) 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. 

 翻译过来是:

额外的非发射事件侦听器(queryList、closeDialog)已传递给组件,但由于组件呈现片段或文本根节点,因此无法自动继承。如果侦听器仅作为组件自定义事件侦听器,请使用“emits”选项声明它。

查了资料才发现是因为子组件调用父组件的方法时有点不一样

之前是这样的:

const emit = defineEmits();
emit("queryList");
emit("closeDialog");

 修改:

const emit = defineEmits(["queryList","closeDialog"]);
emit("queryList");
emit("closeDialog");

把父组件内的方法再在defineEmits里面声明一遍就可以了 

猜你喜欢

转载自blog.csdn.net/wzy_PROTEIN/article/details/131124244
今日推荐