el-checkbox选中条数
时间: 2023-11-24 20:53:20 浏览: 85
nested_el-checkbox:element-ui的el-checkbox实现嵌套多选,单选
5星 · 资源好评率100%
以下是两种获取el-checkbox选中条数的方法:
1.使用el-checkbox-group的v-model数组长度来获取选中条数
```html
<template>
<div>
<el-checkbox-group v-model="checkedCities">
<el-checkbox label="北京"></el-checkbox>
<el-checkbox label="上海"></el-checkbox>
<el-checkbox label="广州"></el-checkbox>
<el-checkbox label="深圳"></el-checkbox>
</el-checkbox-group>
<p>选中了{{checkedCities.length}}个城市</p>
</div>
</template>
<script>
export default {
data() {
return {
checkedCities: []
};
}
};
</script>
```
2.使用单个el-checkbox的v-model值来获取选中条数
```html
<template>
<div>
<el-checkbox v-model="checked1" label="选项1"></el-checkbox>
<el-checkbox v-model="checked2" label="选项2"></el-checkbox>
<el-checkbox v-model="checked3" label="选项3"></el-checkbox>
<p>选中了{{checked1 + checked2 + checked3}}个选项</p>
</div>
</template>
<script>
export default {
data() {
return {
checked1: false,
checked2: false,
checked3: false
};
}
};
</script>
```
阅读全文