javascript - How vue2 dynamically generates a checkbox that is selected by default and obtains data
高洛峰
高洛峰 2017-06-10 09:49:17
0
1
1231

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

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
巴扎黑

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!