vue js - radio button won't check by default with v-model attribute

Mik*_*ell 2 javascript radio-button checked vue.js

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
Run Code Online (Sandbox Code Playgroud)

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

Tay*_*ser 5

只需将该v-model属性设置为您要默认检查的收音机的值即可。

例如:

export default {
  data () {
    return {
      sumType: '-'
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

Subtraction在页面加载时选择收音机。

使用以下 HTML(具有上述组件结构)有效:

<input type="radio" name="sign" value="+" v-model="sumType"> Addition
<input type="radio" name="sign" value="-" v-model="sumType"> Subtraction
Run Code Online (Sandbox Code Playgroud)