O
O
OstapO2019-09-03 14:08:42
Vue.js
OstapO, 2019-09-03 14:08:42

How to temporarily store information about which radio button is selected without using vuex?

I'm trying to make a multi-step form. Question types are separated into separate components and connected in the main MainForm.vue. Now, when moving forward / backward between questions, the selected values ​​are not saved. How can I make the selected answer active when moving between questions?
5d6e473a3c041148742583.jpeg

MainForm.vue

<RadioQuestion key="question1" v-if="step === 1" :answers="qRadio1" />
 <RadioQuestion key="question2" v-if="step === 2" :answers="qRadio2" />


RadioQuestion.vue

<template>
  <div class="row question-step no-image-radio">
    <!-- Start Answer -->
    <div class="col-12" v-for="(answer, idx) in answers" :key="answer.name">
      <label class="question-label" :for="'step'+answer.questionNum+'_' + idx">
        <div class="custom-control custom-radio custom-control-inline">
          <input
            type="radio"
            :id="'step'+answer.questionNum+'_' + idx"
            :name="'step_'+answer.questionNum"
            class="custom-control-input"
            v-model="singleAnswer"
            :value="answer.name"
          />
          <label class="custom-control-label" :for="'step'+answer.questionNum+'_' + idx"></label>
        </div>
        <div class="answer">{{ answer.name }}</div>
      </label>
    </div>
    <!-- End Answer -->
  </div>
</template>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-09-03
@OstapO

Store the selected answers in the parent component, pass them to the questions as parameters, send it to the parent when you select an answer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question