feat(Switch): add click event (#4915)

This commit is contained in:
neverland
2019-11-04 17:58:20 +08:00
committed by GitHub
parent a19d3cc5c0
commit 577174c7f8
5 changed files with 62 additions and 77 deletions
+21 -24
View File
@@ -13,6 +13,8 @@ Vue.use(Switch);
### 基础用法
通过`v-model`绑定开关的选中状态,`true`表示开,`false`表示关
```html
<van-switch v-model="checked" />
```
@@ -29,48 +31,42 @@ export default {
### 禁用状态
通过`disabled`属性来禁用开关,禁用状态下开关不可点击
```html
<van-switch
v-model="checked"
disabled
/>
<van-switch v-model="checked" disabled />
```
### 加载状态
通过`loading`属性设置开关为加载状态,加载状态下开关不可点击
```html
<van-switch
v-model="checked"
loading
/>
<van-switch v-model="checked" loading />
```
### 自定义大小
通过`size`属性自定义开关的大小
```html
<van-switch
v-model="checked"
size="24px"
/>
<van-switch v-model="checked" size="24px" />
```
### 自定义颜色
`active-color`属性表示打开时的背景色,`inactive-color`表示关闭时的背景色
```html
<van-switch
v-model="checked"
active-color="#07c160"
inactive-color="#ee0a24"
/>
<van-switch v-model="checked" active-color="#07c160" inactive-color="#ee0a24" />
```
### 异步控制
需要异步控制开关时,可以使用`value`属性和`input`事件代替`v-model`,并在`input`事件回调函数中手动处理开关状态
```html
<van-switch
:value="checked"
@input="onInput"
/>
<van-switch :value="checked" @input="onInput" />
```
```js
@@ -111,6 +107,7 @@ export default {
### Events
| 事件名 | 说明 | 回调参数 |
|------|------|------|
| change | 开关状态切换回调 | checked: 是否选中开关 |
| 事件名 | 说明 | 回调参数 | 版本 |
|------|------|------|------|
| change | 开关状态切换回调 | checked: 是否选中开关 | - |
| click | 点击时触发 | event: Event | 2.2.11 |