最近用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里面声明一遍就可以了 

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐