diff --git a/packages/switch/README.md b/packages/switch/README.md
index 72ee1e03..875c885b 100644
--- a/packages/switch/README.md
+++ b/packages/switch/README.md
@@ -98,6 +98,8 @@ Page({
| size | 开关尺寸 | `String` | `30px` |
| active-color | 打开时的背景色 | `String` | `#1989fa` |
| inactive-color | 关闭时的背景色 | `String` | `#fff` |
+| active-value | 打开时的值 | `any` | `true` |
+| inactive-value | 关闭时的值 | `any` | `false` |
### Event
diff --git a/packages/switch/index.ts b/packages/switch/index.ts
index 8bf5b019..f83ba923 100644
--- a/packages/switch/index.ts
+++ b/packages/switch/index.ts
@@ -6,7 +6,7 @@ VantComponent({
classes: ['node-class'],
props: {
- checked: Boolean,
+ checked: null,
loading: Boolean,
disabled: Boolean,
activeColor: String,
@@ -14,6 +14,14 @@ VantComponent({
size: {
type: String,
value: '30px'
+ },
+ activeValue: {
+ type: null,
+ value: true
+ },
+ inactiveValue: {
+ type: null,
+ value: false
}
},
@@ -29,10 +37,12 @@ VantComponent({
methods: {
onClick() {
+ const { activeValue, inactiveValue } = this.data;
if (!this.data.disabled && !this.data.loading) {
- const checked = !this.data.checked;
- this.$emit('input', checked);
- this.$emit('change', checked);
+ const checked = this.data.checked === activeValue;
+ const value = checked ? inactiveValue : activeValue;
+ this.$emit('input', value);
+ this.$emit('change', value);
}
}
}
diff --git a/packages/switch/index.wxml b/packages/switch/index.wxml
index e215473c..74ce520e 100644
--- a/packages/switch/index.wxml
+++ b/packages/switch/index.wxml
@@ -1,7 +1,7 @@