2020-08-27 17:18:57 +08:00

103 lines
3.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
pageClass: comp-page-class
---
# Switch 开关
## 概述
需要表示开关状态/两种状态之间的切换时使用。
## 代码示例
<ClientOnly>
<row>
<cell span="12" class="pr-20">
<componetTemplate title="基础用法" template="ui/templates/switch/1.html">
<template v-slot:demo>
<Wb-switch v-model="value"/>
</template>
<template v-slot:description>
<p>在组件中绑定v-model控制开关状态</p>
</template>
</componetTemplate>
<componetTemplate title="文字和图标" template="ui/templates/switch/2.html">
<template v-slot:demo>
<Wb-switch>
<span slot="open"></span>
<span slot="close"></span>
</Wb-switch>
<Wb-switch>
<Icon slot="open" type="md-checkmark"></Icon>
<Icon slot="close" type="md-close"></Icon>
</Wb-switch>
</template>
<template v-slot:description>
<p>自定义内容slot为open的文字或者图标在on为true时显示反之依然。</p>
</template>
</componetTemplate>
</cell>
<cell span="12" class="pl-20">
<componetTemplate title="切换前询问" template="ui/templates/switch/3.html">
<template v-slot:demo>
<Wb-switch :confirm="confirm"></Wb-switch>
</template>
<template v-slot:description>
<p>点击切换时弹出confirm询问点击确定之后才发生切换。</p>
</template>
</componetTemplate>
<componetTemplate title="只读和禁用" template="ui/templates/switch/4.html">
<template v-slot:demo>
<Wb-switch readonly></Wb-switch>
<Wb-switch disabled></Wb-switch>
</template>
<template v-slot:description>
<p>设置readonly为只读设置disabled为禁用</p>
</template>
</componetTemplate>
</cell>
</row>
</ClientOnly>
<style lang="scss">
</style>
<script>
export default {
data() {
return {
value: false
}
},
methods: {
confirm() {
return new Promise((resolve, reject)=>{
this.$Message({
title: '警告', // 可以传入文本和domString
template: '是否切换状态?', // 可以传入文本和domString
}).then(function (index) {
if (index == 0) {
resolve()
}
})
})
},
}
}
</script>
## API
### WbSwitch Props
| 属性 | 说明 | 类型 | 默认值 |
|:--------------|:--------------------------|:--------|:-----------------------------------------------------|
| value | 日期的值可以使用v-model实现数据的双向绑定 | String | null |
| disabled | 是否禁用 | Boolean | false |
| readonly | 是否只读 | Boolean | false |
| confirm | 状态切换前的询问函数返回promise当promise的状态为resolve时执行切换 | Function | null |
### WbSwitch Events
| 事件名 | 说明 | 返回值 |
|:--------------|:--------------------------|:--------|
| on-change | 切换后触发 | (value) => void |