mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
* [Document] add english document of Checkbox * [Document] add english document of Field * [Document] add english document of NumberKeyboard * [bugfix] NumberKeyboard should not dispaly title when title is empty * [Document] add english document of PasswordInput * [Document] add english document of Radio * [document] add english document of Switch * [bugfix] remove redundent styles in english document * [Document] fix details * fix Switch test cases
1.8 KiB
1.8 KiB
Switch
Install
import { Switch } from 'vant';
Vue.component(Switch.name, Switch);
Usage
Basic Usage
:::demo Basic Usage
<van-switch v-model="checked" />
export default {
data() {
return {
checked: true
};
}
};
:::
Disabled
:::demo Disabled
<van-switch v-model="checked" disabled />
:::
Loading
:::demo Loading
<van-switch v-model="checked" loading />
:::
Advanced usage
:::demo Advanced usage
<van-switch :value="checked2" @input="onInput" />
export default {
data() {
return {
checked2: true
};
},
methods: {
onInput(checked) {
Dialog.confirm({
title: 'Confirm',
message: 'Are you sure to toggle switch?'
}).then(() => {
this.checked2 = checked;
});
}
}
};
:::
API
Attribute | Description | Type | Default | Accepted Values |
---|---|---|---|---|
v-model | Check status of Switch | Boolean |
false |
- |
loading | Whether to show loading icon | Boolean |
false |
- |
disabled | Disable switch | Boolean |
false |
- |
Event
Event | Description | Parameters |
---|---|---|
change | Triggered when check status changed | checked: is switch checked |