Extraneous non-emits event listeners (XXX) were passed to component but could not be automatically i

使用vue框架进行父子组件传值的时候,可能会出现如下警告:
Extraneous non-emits event listeners (XXX) 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. 
无关的非发出事件侦听器(XXX)被传递给组件,但不能自动继承,因为组件呈现片段或文本根节点。如果侦听器只打算作为组件自定义事件侦听器,则使用"emit "选项声明它。
XXX是子传父的自定义事件名称
详情如下所示:在这里插入图片描述

原因:

https://github.com/vuejs/core/issues/2540

解决办法:

在需要传递事件的组件中,新增如下代码:
emits: ['XXX'] // 和props是同一级

猜你喜欢

转载自blog.csdn.net/Y1914960928/article/details/133136164
今日推荐