<NuxtPage> events?
I would like to ask whether handling child component events directly in the
<NuxtPage>
component could be considered an anti-pattern. I encountered this solution during a code review by my colleague, and it seems to me like an improper approach.
For example:
It seems highly problematic to me due to the fact that there is no certainty about which component will be rendered in place of <NuxtPage>. As a result, there is no guarantee regarding which events can be handled.3 Replies
Depends on the circumstances. What purpose does the event handler have in this regard?
In this particular case, in the parent component, we are using
<NuxtPage>
to render three different tables based on the routing, on which certain actions can be performed. At the moment, we know the specific child components that may be rendered, but I have a feeling that as the application evolves, we might lose control over this, and the solution seems somewhat fragile. I hope this answers your question.It feels indeed weird to do that. It might not show errors as the recipient does care if the component ever emits an event called
some-event
but you will have a very hard time to debug this in the future.
I'd say for a quick'n dirty page, okay. In general i would not do that.