ct-adc-checkbox-group
Version:
A Vue.js project for selecting checkbox group
125 lines (99 loc) • 2.67 kB
Markdown
> 基于 Vue2.0 的复选框组件
- [Build Setup](
- [在线演示](
- [代码示例](
- [API](
- [props](
- [emit](
``` bash
npm install
npm run dev
npm run build
npm run build --report
```
For detailed explanation on how things work, checkout the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
在线演示: [go to live demo](http://htmlpreview.github.io/?https://github.com/ct-adc/ct-adc-checkbox-group/blob/master/view/demo.html).

```html
<checkbox-group :list="config.list"
:matchedList="config.matchedList"
:showKey="config.showKey"
:matchKey="config.matchKey"
@change="updateMatchedList"></checkbox-group>
```
```javascript
import CheckboxGroup from 'ct-adc-checkbox-group.vue';
export default {
components: {
CheckboxGroup
},
data() {
return {
config: {
showKey: 'name',
matchKey: 'id',
list: [
{
id: 1,
name: '小鹿男'
}
],
matchedList: [
{
id: 1,
name: '小鹿男'
}
]
}
};
},
methods: {
updateMatchedList(aList) {
this.config.matchedList = aList;
}
}
};
```
```javascript
// 总列表
list: {
type: Array,
default() {
return [];
}
},
// 已选择的列表
matchedList: {
type: Array,
default() {
return [];
}
},
// 需要显示的字段
// 目前只支持一个字段显示
showKey: {
type: String,
required: true
},
// 匹配键值[必需唯一]
matchKey: {
type: String,
required: true
}
```
每次选中修改,都将 `emit` 一个 `change` 事件,并传入当前选中的列表,例如:
```javascript
this.$emit('change', this.getCheckedList());
```