0

I have the following three components. Basically I need the submit event from the CustomForm component but its' only passed to the parent component. Is there an easy way to do this? I want to avoid using an event bus.

CustomForm.vue

<template>
  <form @submit.prevent="submit">
    <slot />
  </form>
</template>

<script>
export default {
  methods: {
    submit() {
      this.$emit('onSubmit')
    }
  }
}
</script>

FormHolder.vue

<template>
  <div>
    <CustomForm>
      <slot />
      <FormSubmit />
    </CustomForm>
  </div>
</template>

Page.vue

<template>
    <FormHolder @onSubmit="submit">
      My input fields...
    </FormHolder>
</template>

1 Answer 1

1

Without an event bus or Vuex, you need to bubble up the event so that when CustomForm emits an event, FormHolder emits an event up to Page:

<template>
  <div>
    <CustomForm @onSubmit="submit">
      <slot />
      <FormSubmit />
    </CustomForm>
  </div>
</template>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.