1

How can I display divA when radio button A is checked and display divB when radio button B is checked?

<b-form-radio value="A">A</b-form-radio>
<b-form-radio value="B">B</b-form-radio>

<!-- divA -->

<div>
...
</div>

<!-- divB -->
<div>
...
</div>

1 Answer 1

4

Assuming your custom radio control (b-form-radio) supports v-model, you can do this:

<b-form-radio v-model="selected" value="A">A</b-form-radio>
<b-form-radio v-model="selected" value="B">B</b-form-radio>

<!-- divA -->
<div v-show="selected === 'A'">
...
</div>

<!-- divB -->
<div v-show="selected === 'B'">
...
</div>

Additionally, in your component data function, you need to make selected as a reactive property:

{
  data() {
    return {
      // Initially selected will be null
      // to hide both the div
      selected: null
    }
  }
}

In summary, it is the combination of v-show directive together with v-model. Also, you can use v-if instead of v-show if you do not want other div to be rendered at all on the page.

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.