首页 > 其他 > 详细

vue 实现全选

时间:2018-06-15 15:15:16      阅读:234      评论:0      收藏:0      [点我收藏+]

html:

<p><input type="checkbox" v-model="allSelect"><span>全选</span></p>
<ul class="dataList">
<li v-for="item,index in getDataList" :key="index">
<input type="checkbox" v-model="item.show" />
<span v-text="item.cont"></span>
</li>
</ul>
<p>{{getDataList}}</p>

js:

new Vue({
el: ‘.app‘,
data: {
dataList: [
{
cont: 111,
},
{
cont: 222,
},
{
cont: 333,
},
{
cont: 444,
},
{
cont: 555,
}
]
},
computed: {
getDataList(){
return this.dataList.map(item=>{
this.$set(item,‘show‘,false)
return item
})
},
allSelect: {
get: function(){
return this.getDataList.every(item=>item.show)
},
set: function(newValue){
this.dataList.map(item=>this.$set(item,‘show‘,newValue))
}
}
},
})

vue 实现全选

原文:https://www.cnblogs.com/shenxinze/p/9186747.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!