Files
element/examples/docs/checkbox.md
2016-08-12 14:45:06 +08:00

111 lines
2.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script>
module.exports = {
data() {
return {
checkList: ['选中且禁用','复选框 A'],
// checkList2: ['复选框 A'],
checked: true,
name: 'Jonny',
a: 'Jonny',
b: 'Lara'
};
}
};
</script>
<style>
.demo-box.demo-checkbox {
.checkbox {
margin-right: 5px;
& + .checkbox {
margin-left: 10px;
}
}
}
</style>
## 基础用法
### 单个勾选框,逻辑值
<div class="demo-box demo-checkbox">
<el-checkbox class="checkbox" v-model="checked">{{ checked }}</el-checkbox>
</div>
```html
<el-checkbox class="checkbox" v-model="checked">{{ checked }}</el-checkbox>
```
### 多个勾选框,绑定到同一个数组
<div class="demo-box demo-checkbox">
<el-checkbox class="checkbox" v-model="checkList" label="复选框 A"></el-checkbox>
<el-checkbox class="checkbox" v-model="checkList" label="复选框 B"></el-checkbox>
<el-checkbox class="checkbox" v-model="checkList" label="复选框 C"></el-checkbox>
<el-checkbox class="checkbox" v-model="checkList" label="禁用" disabled></el-checkbox>
<el-checkbox class="checkbox" v-model="checkList" label="选中且禁用" disabled></el-checkbox>
</div>
<p>{{ checkList }}</p>
```html
<template>
<el-checkbox class="checkbox" v-model="checkList" label="复选框 A"></el-checkbox>
<el-checkbox class="checkbox" v-model="checkList" label="复选框 B"></el-checkbox>
<el-checkbox class="checkbox" v-model="checkList" label="复选框 C"></el-checkbox>
<el-checkbox class="checkbox" v-model="checkList" label="禁用" disabled></el-checkbox>
<el-checkbox class="checkbox" v-model="checkList" label="选中且禁用" disabled></el-checkbox>
</template>
<script>
export default {
data () {
return {
checkList: ['选中且禁用','复选框 A']
}
}
}
</script>
```
### 绑定 value
<div class="demo-box demo-checkbox">
<el-checkbox
class="checkbox"
v-model="name"
:true-label="a"
:false-label="b">
{{name}}
</el-checkbox>
</div>
```html
<el-checkbox
class="checkbox"
v-model="name"
:true-label="a"
:false-label="b">
{{name}}
</el-checkbox>
```
```js
vm.a = 'Jonny';
vm.b = 'Lara';
// 当选中时
vm.name === vm.a
// 当没有选中时
vm.name === vm.b
```
## API
| 参数 | 说明 | 类型 | 可选值 | 默认值 |
|---------- |-------- |---------- |------------- |-------- |
| model | 绑定值 | string\|string[]\|boolean | | |
| value | 真实值 | string | | |
| label | 显示值,不填则显示 value | string | | |
| disabled | 禁用 | boolean | true, false | false |