2018-03-09 05:26:34 +00:00
|
|
|
<cn>
|
|
|
|
#### 全选
|
|
|
|
在实现全选效果时,你可能会用到`indeterminate`属性
|
|
|
|
</cn>
|
|
|
|
|
|
|
|
<us>
|
2018-03-09 09:50:33 +00:00
|
|
|
#### Check all
|
2018-03-09 05:26:34 +00:00
|
|
|
The `indeterminate` property can help you to achieve a 'check all' effect.
|
|
|
|
</us>
|
|
|
|
|
2019-10-09 10:32:23 +00:00
|
|
|
```tpl
|
2018-03-09 05:26:34 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div :style="{ borderBottom: '1px solid #E9E9E9' }">
|
2019-09-28 12:45:07 +00:00
|
|
|
<a-checkbox :indeterminate="indeterminate" @change="onCheckAllChange" :checked="checkAll">
|
2018-03-09 05:26:34 +00:00
|
|
|
Check all
|
|
|
|
</a-checkbox>
|
|
|
|
</div>
|
|
|
|
<br />
|
|
|
|
<a-checkbox-group :options="plainOptions" v-model="checkedList" @change="onChange" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2019-09-28 12:45:07 +00:00
|
|
|
const plainOptions = ['Apple', 'Pear', 'Orange'];
|
|
|
|
const defaultCheckedList = ['Apple', 'Orange'];
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
checkedList: defaultCheckedList,
|
|
|
|
indeterminate: true,
|
|
|
|
checkAll: false,
|
|
|
|
plainOptions,
|
|
|
|
};
|
2018-03-09 05:26:34 +00:00
|
|
|
},
|
2019-09-28 12:45:07 +00:00
|
|
|
methods: {
|
|
|
|
onChange(checkedList) {
|
|
|
|
this.indeterminate = !!checkedList.length && checkedList.length < plainOptions.length;
|
|
|
|
this.checkAll = checkedList.length === plainOptions.length;
|
|
|
|
},
|
|
|
|
onCheckAllChange(e) {
|
|
|
|
Object.assign(this, {
|
|
|
|
checkedList: e.target.checked ? plainOptions : [],
|
|
|
|
indeterminate: false,
|
|
|
|
checkAll: e.target.checked,
|
|
|
|
});
|
|
|
|
},
|
2018-03-09 05:26:34 +00:00
|
|
|
},
|
2019-09-28 12:45:07 +00:00
|
|
|
};
|
2018-03-09 05:26:34 +00:00
|
|
|
</script>
|
|
|
|
```
|