mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
Checkbox: support change event
This commit is contained in:
parent
c061e0fb26
commit
ca9379de0d
@ -45,8 +45,7 @@ Vue.component(Checkbox.name, Checkbox);
|
|||||||
### 代码演示
|
### 代码演示
|
||||||
|
|
||||||
#### 基础用法
|
#### 基础用法
|
||||||
|
通过`v-model`绑定 checkbox 的勾选状态
|
||||||
通过`v-model`绑定值即可。当`Checkbox`选中时,绑定的值即为`true`,否则为`false`。当单个`Checkbox`使用时,更建议使用`Switch`组件。
|
|
||||||
|
|
||||||
:::demo 基础用法
|
:::demo 基础用法
|
||||||
```html
|
```html
|
||||||
|
@ -31,22 +31,23 @@ export default {
|
|||||||
mixins: [findParent],
|
mixins: [findParent],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
disabled: Boolean,
|
|
||||||
value: {},
|
value: {},
|
||||||
|
disabled: Boolean,
|
||||||
name: [String, Number]
|
name: [String, Number]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
value(val) {
|
||||||
|
this.$emit('change', val);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
/**
|
// checkbox 是否在 van-checkbox-group 中
|
||||||
* `checkbox`是否在`van-checkbox-group`中
|
|
||||||
*/
|
|
||||||
isGroup() {
|
isGroup() {
|
||||||
return !!this.findParentByComponentName('van-checkbox-group');
|
return !!this.findParentByComponentName('van-checkbox-group');
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* `checkbox`当前值
|
|
||||||
*/
|
|
||||||
currentValue: {
|
currentValue: {
|
||||||
get() {
|
get() {
|
||||||
return this.isGroup && this.parentGroup ? this.parentGroup.value.indexOf(this.name) !== -1 : this.value;
|
return this.isGroup && this.parentGroup ? this.parentGroup.value.indexOf(this.name) !== -1 : this.value;
|
||||||
@ -75,9 +76,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* `checkbox`是否被选中
|
|
||||||
*/
|
|
||||||
isChecked() {
|
isChecked() {
|
||||||
const currentValue = this.currentValue;
|
const currentValue = this.currentValue;
|
||||||
if ({}.toString.call(currentValue) === '[object Boolean]') {
|
if ({}.toString.call(currentValue) === '[object Boolean]') {
|
||||||
@ -87,9 +85,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* `checkbox`是否被禁用
|
|
||||||
*/
|
|
||||||
isDisabled() {
|
isDisabled() {
|
||||||
return this.isGroup && this.parentGroup
|
return this.isGroup && this.parentGroup
|
||||||
? this.parentGroup.disabled
|
? this.parentGroup.disabled
|
||||||
|
Loading…
x
Reference in New Issue
Block a user