Skip to content

FxSwitch 开关

在两种状态间切换。不依赖任何 UI 框架,颜色走 @fx/styles--color-* token。

基础用法

尺寸

sizelarge / default / small

文字描述

active-text / inactive-text 显示文字;inline-prompt 将文字放进圆点。

自定义图标

active-icon / inactive-icon(两侧图标)及 active-action-icon / inactive-action-icon(圆点内图标),值为 FxIcon name。

扩展值类型

active-value / inactive-value 可为任意类型(字符串/数字等)。

禁用

加载中

阻止切换

before-change 返回 booleanPromise<boolean>,返回 false / reject 阻止切换。

圆点动作图标

active-action-icon / inactive-action-icon 仅作用于圆点。

圆点动作插槽

active-action / inactive-action 插槽自定义圆点内容。

API

Attributes

属性说明类型默认值
v-model / modelValue绑定值boolean | string | numberfalse
disabled是否禁用booleanfalse
loading是否加载中booleanfalse
size尺寸'large' | 'default' | 'small'default
width宽度(数字按 px)string | number''
inline-prompt文字/图标是否显示在圆点内booleanfalse
active-icon开启时图标string(IconString)
inactive-icon关闭时图标string(IconString)
active-action-icon开启时圆点图标string(IconString)
inactive-action-icon关闭时圆点图标string(IconString)
active-text开启文字string''
inactive-text关闭文字string''
active-value开启时的值boolean | string | numbertrue
inactive-value关闭时的值boolean | string | numberfalse
nameinput namestring''
before-change切换前钩子() => boolean | Promise<boolean>
tabindextabindexstring | number
aria-label原生 aria-labelstring

Slots

插槽名说明
active开启时内容
inactive关闭时内容
active-action开启时圆点内容
inactive-action关闭时圆点内容

Events

事件名说明类型
update:modelValue值变化(val: any) => void
change值变化(val: any) => void
input值变化(input)(val: any) => void

Exposes

方法说明
focus聚焦开关
checked当前是否选中