请问在vue3中该如何在子组件中判断emit注册的方法父组件是否传入呢? #8092
-
vue2中可以使用$listeners,那么vue3呢?我尝试使用useAttrs,但是即使父组件使用了v-on传入,也并不能通过useAttrs找到emit中所定义的。我清楚父组件中使用v-bind就可以找到,但是这就不使用emit了,还是有点疑惑该如何判断使用emit注册的方法父组件是否传入呢? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
你可以参考v-model的原理在结合一下jsx中的写法推导出 @change =>onChange |
Beta Was this translation helpful? Give feedback.
-
可以用useAttrs去检查,例如 useAttrs()['onChange'] |
Beta Was this translation helpful? Give feedback.
-
太复杂了, 现在有好的判断方法吗, 因为有些方法不是必须传递的 |
Beta Was this translation helpful? Give feedback.
-
vue 合并 defineProps 和 defineEmits 就没这问题了 |
Beta Was this translation helpful? Give feedback.
-
can u explain on english and i try help u xD |
Beta Was this translation helpful? Give feedback.
你可以参考v-model的原理在结合一下jsx中的写法推导出 @change =>onChange
demo