checkbox.vue
3.37 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template>
<div>
<Checkbox v-model="single" @on-change="s">Checkbox</Checkbox>
{{ single }}
<div @click="single = !single">single-change</div>
<br>
{{ social }}
<Checkbox-group v-model="social" @on-change="s">
<Checkbox label="twitter">
<Icon type="social-twitter"></Icon>
<span>Twitter</span>
</Checkbox>
<Checkbox label="facebook">
<Icon type="social-facebook"></Icon>
<span>Facebook</span>
</Checkbox>
<Checkbox label="github">
<Icon type="social-github"></Icon>
<span>Github</span>
</Checkbox>
<Checkbox label="snapchat">
<Icon type="social-snapchat"></Icon>
<span>Snapchat</span>
</Checkbox>
</Checkbox-group>
<br>
<div @click="c">修改1</div>
{{ fruit }}
<Checkbox-group v-model="fruit">
<Row>
<i-col span="8">
<Checkbox label="香蕉"></Checkbox>
</i-col>
<i-col span="8">
<Checkbox label="苹果"></Checkbox>
</i-col>
<i-col span="8">
<Checkbox label="西瓜"></Checkbox>
</i-col>
</Row>
</Checkbox-group>
<br><br>
<div style="border-bottom: 1px solid #e9e9e9;padding-bottom:6px;margin-bottom:6px;">
<Checkbox
:indeterminate="indeterminate"
v-model="checkAll"
@click.prevent.native="handleCheckAll">全选</Checkbox>
</div>
<Checkbox-group v-model="checkAllGroup" @on-change="checkAllGroupChange">
<Checkbox label="香蕉"></Checkbox>
<Checkbox label="苹果"></Checkbox>
<Checkbox label="西瓜"></Checkbox>
</Checkbox-group>
</div>
</template>
<script>
export default {
data () {
return {
social: ['facebook', 'github'],
fruit: ['苹果'],
single: false,
indeterminate: true,
checkAll: false,
checkAllGroup: ['香蕉', '西瓜']
}
},
methods: {
c () {
this.social.splice(0, 1)
},
s (d) {
console.log(d)
},
handleCheckAll () {
if (this.indeterminate) {
this.checkAll = false;
} else {
this.checkAll = !this.checkAll;
}
this.indeterminate = false;
if (this.checkAll) {
this.checkAllGroup = ['香蕉', '苹果', '西瓜'];
} else {
this.checkAllGroup = [];
}
},
checkAllGroupChange (data) {
if (data.length === 3) {
this.indeterminate = false;
this.checkAll = true;
} else if (data.length > 0) {
this.indeterminate = true;
this.checkAll = false;
} else {
this.indeterminate = false;
this.checkAll = false;
}
}
}
}
</script>