2

If I remove the v-model attribute, checked works.

<input type="radio" name="sign" value="+" v-model="sumType" checked="checked"> Addition
<input type="radio" name="sign" value="-" v-model="sumType"> Subtraction

How do I default check a radio button that has a vue js model attribute?

2 Answers 2

5

Just set the v-model property to the value of the radio that you want to be checked by default.

For example:

export default {
  data () {
    return {
      sumType: '-'
    }
  }
}

would select the Subtraction radio on page load.

Using the following HTML (with the above component structure) works:

<input type="radio" name="sign" value="+" v-model="sumType"> Addition
<input type="radio" name="sign" value="-" v-model="sumType"> Subtraction
Sign up to request clarification or add additional context in comments.

Comments

2

sumType model's value overrides your checked attribute.

Probably, you want to specify the binding value (v-bind:value=""):

<input type="radio" name="sign" value="+" v-bind:value="+" v-model="sumType"> Addition
<input type="radio" name="sign" value="-" v-bind:value="-" v-model="sumType"> Subtraction

1 Comment

May be, '+' should be wrapped with strings, v-bind:value=" '+' " rather just v-bind:value="+"

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.