I want to emit a event from a index component to default layout.
I know if I want to emit event to default layout, I can use $nuxt.$emit, but my project is using nuxt composition api. In this situation, is it still can emit event to default layout?
in child component, I will use this function.
const updateList = () => {
emit('update');
}
but layout can't get this update event.
I want to use $nuxt.$emit in composition api component.
How to use $nuxt.$emit in composition api component?
Composition API setup function takes two parameters: setup(props, context). Context contains emit function you are looking for.
You either need to call it as context.emit('someEvenet') or use destructuring in setup as setup(props, { emit }) and use it like you would conventionally
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With