javascript - After the value of the checkbox is bound to the instance on Vue, it cannot be selected by default (checked is invalid)
滿天的星座
滿天的星座 2017-05-19 10:31:41
0
1
652
<p id="form-1">
    <input type="checkbox" id="checkbox" v-model="toggle" :true-value='a' :false-value='b'>
    <label for="checkbox">{{ toggle }}</label>
</p>
    

JS

new Vue({
            el:'#form-1',
            data:{
                toggle:true,
                a:'选了',
                b:'没选'
            }
        })

Now I want this check box to be selected by default and the value is 'selected'. How should I write it?

滿天的星座
滿天的星座

reply all(1)
给我你的怀抱
<input type="checkbox" id="checkbox" v-model="toggle">
<label for="checkbox">{{ toggle ? '选中' : '未选中' }}</label>
new Vue({
  el: '#form-1',
  data: {
    toggle: true
  }
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template