3

I am making a course evaluation form, I have question components inside of it like this:

<question v-for="(question,index) in questions"
                :questionText="question.questionText"
                :question-index="++index"
                ref="questions"> </question>

each question has radio button and a result field connected with v-modal. I want to submit the result for each question to firebase database.

I need to either access the result from evaluation-form (parent) or have a submit function in question component and call it to make each question submit its data.

I tried refs but I failed, I also find events quite hard, what is the easiest way?

1

1 Answer 1

1

I figured out the solution with events:

For those who are also having a hard time with events

Here is my solution:

On question (child):

            <input type="radio" :value="point" v-on:click="sendAnswer(point)" v-bind:name="'answer' + questionIndex">

methods: {
  sendAnswer: function(point) {
    this.answer = point;
    const index = this.questionIndex-1;
    this.$emit('send-answer', {answer: this.answer, index: index});
  },
}

On parent:

<question v-for="(question,index) in questions"
                    :questionText="question.questionText"
                    :question-index="++index"
                    @send-answer="getAnswer"> </question>
    getAnswer(e) {
      this.answers[e.index] = e.answer;
    }
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.