mercredi 7 août 2019

I want to make a radio-like checkbox in VueJs

I want to make a radio-like checkbox in VueJs.

This is the code I have already written. https://jsfiddle.net/WeiChienHsing/w4nxhLg2/

Since I am new to VueJs,I wonder whether there is a more concise way to accomplish this?

 <div id="div">
   <div v-for="(item,index) in items">
     <input type="checkbox" v-model="items[index]" v-on:click="chkEvent($event, index)" v-bind:id="'jslib' + (index + 1)" value="1" />
     <label v-bind:for="'jslib' + (index + 1)"></label>
   </div>
 </div>

 new Vue({
   el: '#div',
   data: function() {
     return {
       items: new Array(5),
       names: ["VueJs", "ReactJs", "Angular", "jQuery", "BackBoneJs"]
     };
   },
   methods: {
     chkEvent: function(event, idx) {
       if (this.items[idx] == true) {
         event.preventDefault();
       }
       this.items.fill(false);
       this.items[idx] = true;
     }
   }
 })




Aucun commentaire:

Enregistrer un commentaire