N
Nuxt5mo ago
Maciej

<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:
<NuxtPage
@some-event="handleEvent"
/>
<NuxtPage
@some-event="handleEvent"
/>
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
Cue
Cue5mo ago
Depends on the circumstances. What purpose does the event handler have in this regard?
Maciej
MaciejOP5mo ago
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.
Single
Single5mo ago
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.
Want results from more Discord servers?
Add your server