Appearance
SwitchDispatcher
Element Plus 的 el-switch 组件分发器,添加了只读功能。
基本用法
vue
<template>
<el-switch-dispatcher v-model="value" />
</template>
<script lang="ts" setup>
import { ref } from 'vue'
const value = ref(false)
</script>
隐藏源码
尺寸
CloseOpen
CloseOpen
CloseOpen
vue
<template>
<el-switch-dispatcher
v-model="value"
size="large"
active-text="Open"
inactive-text="Close"
/>
<br />
<el-switch-dispatcher
v-model="value"
active-text="Open"
inactive-text="Close"
/>
<br />
<el-switch-dispatcher
v-model="value"
size="small"
active-text="Open"
inactive-text="Close"
/>
</template>
<script lang="ts" setup>
import { ref } from "vue";
const value = ref(true);
</script>
隐藏源码
文字描述
使用active-text属性与inactive-text属性来设置开关的文字描述。 使用 inline-prompt 属性来控制文本是否显示在点内。
使用active-text属性与inactive-text属性来设置开关的文字描述。
Pay by yearPay by month
Pay by yearPay by month
是
Y
超出省略
完整展示多个内容
vue
<template>
<el-switch-dispatcher
v-model="value1"
class="mb-2"
active-text="Pay by month"
inactive-text="Pay by year"
/>
<br />
<el-switch-dispatcher
v-model="value2"
class="mb-2"
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
active-text="Pay by month"
inactive-text="Pay by year"
/>
<br />
<el-switch-dispatcher
v-model="value3"
inline-prompt
active-text="是"
inactive-text="否"
/>
<el-switch-dispatcher
v-model="value4"
class="ml-2"
inline-prompt
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
active-text="Y"
inactive-text="N"
/>
<el-switch-dispatcher
v-model="value6"
class="ml-2"
width="60"
inline-prompt
active-text="超出省略"
inactive-text="超出省略"
/>
<el-switch-dispatcher
v-model="value5"
class="ml-2"
inline-prompt
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
active-text="完整展示多个内容"
inactive-text="多个内容"
/>
</template>
<script lang="ts" setup>
import { ref } from "vue";
const value1 = ref(true);
const value2 = ref(true);
const value3 = ref(true);
const value4 = ref(true);
const value5 = ref(true);
const value6 = ref(true);
</script>
隐藏源码
显示自定义图标
使用 inactive-icon 和 active-icon 属性来添加图标。 使用 inline-prompt 属性来控制图标显示在点内。
vue
<template>
<el-switch-dispatcher
v-model="value1"
:active-icon="Check"
:inactive-icon="Close"
/>
<br />
<el-switch-dispatcher
v-model="value2"
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
inline-prompt
:active-icon="Check"
:inactive-icon="Close"
/>
<br />
<el-switch-dispatcher
v-model="value3"
:active-action-icon="View"
:inactive-action-icon="Hide"
/>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { Check, Close, View, Hide } from "@element-plus/icons-vue";
const value1 = ref(true);
const value2 = ref(true);
const value3 = ref(false);
</script>
隐藏源码
扩展的 value 类型
vue
<template>
<el-tooltip :content="'Switch value: ' + value" placement="top">
<el-switch-dispatcher
v-model="value"
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
active-value="100"
inactive-value="0"
/>
</el-tooltip>
</template>
<script lang="ts" setup>
import { ref } from "vue";
const value = ref("100");
</script>
隐藏源码
禁用状态
vue
<template>
<el-switch-dispatcher v-model="value1" disabled />
</template>
<script lang="ts" setup>
import { ref } from "vue";
const value1 = ref(true);
</script>
隐藏源码
Slots
使用 slots 中的 ${Config.namespace}Reader, ${Config.namespace}Writer 覆盖读写状态渲染函数。
writer: false
vue
<template>
<el-switch-dispatcher v-model="value">
<template #[`${Config.namespace}Reader`]>
<span style="color: green" key="reader">reader: {{ value }}</span>
</template>
<template #[`${Config.namespace}Writer`]>
<span style="color: red" key="writer">writer: {{ value }}</span>
</template>
</el-switch-dispatcher>
</template>
<script lang="ts" setup>
import { ref } from "vue";
import { Config } from "element-plus-form-dispatcher";
const value = ref(false);
</script>
隐藏源码
API
与 el-switch 的 props attrs slots 完全一致