vant/packages/switch/index.vue
neverland 9084a662c3 [Document] add form components english document (#199)
* [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
2017-10-12 07:06:27 -05:00

36 lines
749 B
Vue

<template>
<div class="van-switch" :class="[`van-switch--${value ? 'on' : 'off'}`, { 'van-switch--disabled': disabled }]" @click="toggleState">
<div class="van-switch__node van-hairline-surround">
<van-loading v-if="loading" class="van-switch__loading" />
</div>
<div class="van-switch__bg"></div>
</div>
</template>
<script>
import Loading from '../loading';
export default {
name: 'van-switch',
components: {
[Loading.name]: Loading
},
props: {
value: Boolean,
loading: Boolean,
disabled: Boolean
},
methods: {
toggleState() {
if (!this.disabled && !this.loading) {
this.$emit('input', !this.value);
this.$emit('change', !this.value);
}
}
}
};
</script>