2

I was building a step form and i would like to perform validation and fetch data from my child component.

So i have a step form which ive separated into container(parent) and step1(child)

THe child has form data

IN the child i have

<template>
     thre is the form fiedls
</template>
<script>
 data:()=>({
    orderform:{
      first_name:'',
      lastname:''
    }
  }),

methods:{

 submitOrder(){
  this.$validator.validateAll()
     .then(
      (res)=>{
        if(res){
           //pass this.orderform to parent component

         }   

       }
      )

  }


 }

Now in the parent

<script>
   methods:{

    gotonextStep(){
       //here execute submitOrder function in the child mcomponent
       //am stuck
       //also retrieve order form data here.


    }



    }

</script>

How do i execute the function in the child component and retrieve data fom the parent component.

UPDATE ON PARENT STRUCTURE

<stepper>
 <v-stepper-content step="1">
         <child-1></child-1>
    <button  @click.native="gotonextStep">Continue</v-btn>
  </v-stepper-content>
  ...other stepper steps
</stepper>

2 Answers 2

2

Use a ref

<child-1 ref="child1"></child-1>

Then in the parent you can call methods or get data from the child:

methods:{
  goToNextStep(){
     // call child method
     let methodResult = this.$refs.child1.someChildMethod()
     // access data properties in the child
     let childData = this.$refs.child1.someChildDataProperty
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

CHILD Component

submitOrder(){
  var that = this;
  this.$validator.validateAll()
     .then(
      (res)=>{
        if(res){
           //pass this.orderform to parent component
           that.emit('childValidated',this.orderform);

         }   

       }
      )

  }

Parent Component

<child-component-name @childValidated="gotonextStep"></child-component-name>

methods:{

gotonextStep(dataFromChild){
   //here execute submitOrder function
   //am stuck
   //also retrieve order form data here.
}
} </script>

1 Comment

what am trying to do is execute the child component function while am in the parent component. Thanks for the insight on the emit.

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.