请问在vue3中该如何在子组件中判断emit注册的方法父组件是否传入呢? #8092
Answered
by
chenxch
tiandaixin
asked this question in
Help/Questions
-
vue2中可以使用$listeners,那么vue3呢?我尝试使用useAttrs,但是即使父组件使用了v-on传入,也并不能通过useAttrs找到emit中所定义的。我清楚父组件中使用v-bind就可以找到,但是这就不使用emit了,还是有点疑惑该如何判断使用emit注册的方法父组件是否传入呢? |
Beta Was this translation helpful? Give feedback.
Answered by
chenxch
Apr 17, 2023
Replies: 3 comments 4 replies
-
你可以参考v-model的原理在结合一下jsx中的写法推导出 @change =>onChange |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
tiandaixin
-
可以用useAttrs去检查,例如 useAttrs()['onChange'] |
Beta Was this translation helpful? Give feedback.
0 replies
-
太复杂了, 现在有好的判断方法吗, 因为有些方法不是必须传递的 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
你可以参考v-model的原理在结合一下jsx中的写法推导出 @change =>onChange
demo