Me gustaría pasar este método del componente principal al componente secundario, déjame explicarte: cuando hago clic en el botón de confirmación en mi modal (componente secundario), debe enviar los datos del formulario principal (componente principal)
el método del componente principal:
<b-form @submit.prevent="onSubmit"> ....... </b-form> async onSubmit() { this.errors = false; await this.$store.commit('commit_contractable_id', this.id) await this.$store.dispatch('create_contract', this.form) },mi modal de botón de componente secundario:
<button type="submit" class="btn btn-lg btn-outline-primary w-50" data-dismiss="modal"> Confirm </button>quiero que cuando haga clic en confirmar ejecute la función que está en el componente principal
Use Emit (según el comentario de @ljubadr).
Componente hijo: '¡Hola, padre! ¡Esta cosa sucede!
Componente principal: '¡¿En serio?! ¡Entonces haré esto entonces!'
Componente hijo:
methods: { doSomething() { this.$emit('foobar'); // You can also send up a value(object) }Componente principal:
<template> <child-component @foobar="doThisThing" /> </template> <script> ... methods: { doThisThing() {.... ... </script>