Phoebe
Phoebe

Reputation: 31

How to emit event to default layout in nuxt composition api?

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?

Upvotes: 3

Views: 2373

Answers (1)

Sugar_F0x
Sugar_F0x

Reputation: 74

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

Upvotes: 2

Related Questions