-
Notifications
You must be signed in to change notification settings - Fork 4
/
source.vue
84 lines (75 loc) · 2.06 KB
/
source.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
<div class="center_wrap">
<div class="top">
<div class="line1">
<div >品牌</div>
<div v-for="item in brand">
<input type="checkbox" :id="item.id" :value="item.id" v-model="item.state">
<label :for="item.id">{{item.name}}</label>
</div>
</div>
</div>
</div>
</template>
<script >
export default{
data(){
return{
brand:[
{name:'全部',id:0,state:false,last_state:false},
{name:'tata',id:1,state:false},
{name:'fifa',id:2,state:false},
{name:'baili',id:3,state:false}
],
brand_checked:[],
}
},
watch:{
'brand':{
handler:function(){
//全选
if(this.brand[0].state == true && this.brand[0].last_state == false){
this.brand.forEach(v=>{
v.state = true
})
this.brand[0].last_state = true
return
}
//去掉全选
if(this.brand[0].state == false && this.brand[0].last_state == true){
this.brand.forEach(v=>{
v.state = false
})
this.brand[0].last_state = false
return
}
this.brand_checked = []
this.brand_checked = this.brand.filter( (item,index)=>{
return item.state == true
})
// console.log(this.brand_checked)
//子达到全选
if(this.brand[0].state == false && (this.brand_checked.length == this.brand.length-1)){
this.brand[0].state = true
this.brand[0].last_state = true
return
}
//全选去掉子
if(this.brand[0].state == true && (this.brand_checked.length == this.brand.length-1)){
this.brand[0].state = false
this.brand[0].last_state = false
this.brand_checked = []
return
}
},
deep:true
}
},
methods:{
}
}
</script>
<style lang="scss" scoped>
.center_wrap{
}
</style>