search

Home  >  Q&A  >  body text

javascript - How vue2 dynamically generates a checkbox that is selected by default and obtains data

As in the title:

<li v-for="item in artistsList">
       <img :src="item.user_avatar" alt="">
       <p>
       <p>{{item.user_name}}</p>
       <span>{{item.user_job}}/{{item.user_country}}</span>
     </p>
     <label>
      <input type="checkbox" :value="item.user_id" v-model="userID">
     </label>
</li>

data () {
    return {
      userID:[],
      artistsList:[]
    }
  },

When artistsList is mounted, it will load the data and generate the list by itself, but if you want it to be in the checked state when input is generated, what should you do?
It works if userID is set to true, but when I click on any of the checkboxes, all operations will be performed, similar to selecting all and canceling all selections.
My requirements are as follows:
1. It is selected by default when generating
2. When I select and operate any checkbox, the userId data in the data will be dynamically updated. Let’s talk about what friends do

高洛峰高洛峰2764 days ago1338

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-06-10 09:51:17

    v-model="item.userID" will do,
    item.userID is a Boolean value

    reply
    0
  • Cancelreply