18910140161

动态组件,使用v-bind=\"$attrs\",报警告

2021-10-22 18:18:56

352

《mycom》《component :is=“currentComponent” ref=“refDialogContent” v-bind="$attrs"》《/component》《/mycom》


顺晟科技:

这是传递过去了不能,,,,的属性,感觉没啥大问题。程序是否可以正常运行?

v-bind="$attrs" 绑定虽然生效,但是控制台报警告,提示如下:Extraneous non-emits event listeners (afterSave) 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.请问,需要怎么解决掉报警。内置组件《component》本身就是对应多组件的,感觉没办法了,谢谢。。。

谢谢,这样是可行的。不过我是封装模态框通用组件用的,如果需要特殊处理,那可能用slot代替动态组件更方便。刚开始是使用slot的,不过slot是在父页面渲染,导致模态框打开事件opened里组件还没有渲染出来,需要延迟处理或者其它处理。无意中,用这个动态组件,发现打开事件中opened,竟然渲染出来了,这样就方便了,就是数据绑定时,控制台报警告。。

建议把$attrs拷贝给一个表达式,比如 attribute,并且利用监听器监听$attrs的变化,相应的改变attribute

相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航