首页 > 其他 > 详细

vue全选与取消全选

时间:2019-01-13 00:01:08      阅读:63      评论:0      收藏:0      [点我收藏+]

标签:NPU   rip   modules   charset   html   checked   char   init   utf-8   

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="../node_modules/vue/dist/vue.js"></script>
</head>
<body>
<div id="my">
 
<input type="checkbox" :checked="all" @click="changeAll()"/> 全选
<ul>
<li v-for="(v,i) in items">
<input type="checkbox" :checked="v.status" :index="i" @click="changeItems(i)"/> {{v.name}}
</li>
</ul>
</div>
<script>
let vm = new Vue({
el:"#my",
data:{
all:true,
items:[
{name:‘手机‘,status:false},
{name:‘电脑‘,status:false},
{name:‘平板‘,status:true},
{name:‘包包‘,status:false}
],
selectValue:[]
},
methods:{
changeAll(){
let self = this;
this.all = !this.all
this.items.forEach((val)=>{
val.status = self.all
})
},
changeItems(i){
this.items[i].status = !this.items[i].status;
let itemsStatus = this.items.every((val)=>{
return val.status
})
console.log(itemsStatus)
if(itemsStatus){
this.all = true
}else{
this.all = false
}
}
},
mounted(){
let itemsStatus = this.items.every((val)=>{
return val.status
})
console.log(itemsStatus)
if(itemsStatus){
this.all = true
}else{
this.all = false
}
}
 
})
</script>
</body>
</html>

vue全选与取消全选

标签:NPU   rip   modules   charset   html   checked   char   init   utf-8   

原文:https://www.cnblogs.com/MDGE/p/10261264.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号