M
M
Merle72020-06-24 06:36:12
Vue.js
Merle7, 2020-06-24 06:36:12

How to draw a block if the radio button is pressed?

For the questionnaire, there is a component with a template, there is a block with the answer and there is a block with an additional field for the comment to the answer. It is necessary that by default the block for the comment is not shown, but gets out only when the radio button with the answer is selected.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2020-06-24
@Merle7

<div id="app">
  <input type="radio" id="one" value="Один" v-model="picked">
  <label for="one">Один</label>
  <br>
  <input type="radio" id="two" value="Два" v-model="picked">
  <label for="two">Два</label>
  <br>
  <span>Выбрано: {{ picked }}</span><br>
  <input type="text" v-if="showComment">
</div>

const vm = new Vue({
  el: "#app",
  data: {
    picked : '',
    showComment: false
  },
  watch: {
    picked (){
      this.showComment = (this.picked == 'Два');
    }
  }
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question