Skip to content

Switch 开关

表示两种相互对立的状态间的切换,多用于触发「开/关」。

基础用法

绑定 v-model 到一个 Boolean 类型的变量。

vue
<ivy-switch v-model="value1"></ivy-switch>
<ivy-switch v-model="value1"></ivy-switch>

禁用状态

设置 disabled 属性,接受一个 Boolean,设置 true 即可禁用。

vue
<ivy-switch v-model="value2" disabled class="margin-right-large"></ivy-switch>
<ivy-switch v-model="value1" disabled></ivy-switch>
<ivy-switch v-model="value2" disabled class="margin-right-large"></ivy-switch>
<ivy-switch v-model="value1" disabled></ivy-switch>

扩展的 value 类型

你可以设置 active-valueinactive-value 属性, 它们接受 BooleanStringNumber 类型的值。

vue
<ivy-switch v-model="value3" active-value="1" inactive-value="0"></ivy-switch>
<ivy-switch v-model="value3" active-value="1" inactive-value="0"></ivy-switch>

文字描述

使用 active-text 属性与 inactive-text 属性来设置开关的文字描述。如果文字过长可以修改--ivy-switch-width--ivy-switch-height 手动控制元素的大小

vue
<ivy-switch v-model="value1" active-text="开" inactive-text="关"></ivy-switch>
<ivy-switch
  v-model="value1"
  active-text="开启状态"
  inactive-text="关闭状态"
  width="90px"
  style="--ivy-switch-width:90px;--ivy-switch-height:30px"
  class="margin-left-large"
></ivy-switch>
<ivy-switch v-model="value1" active-text="开" inactive-text="关"></ivy-switch>
<ivy-switch
  v-model="value1"
  active-text="开启状态"
  inactive-text="关闭状态"
  width="90px"
  style="--ivy-switch-width:90px;--ivy-switch-height:30px"
  class="margin-left-large"
></ivy-switch>

Props

参数说明类型可选值默认值
model-value/v-modelswitch的状态String/Boolean/number-false
disabled是否禁用Boolean-false
active-textswitch 的状态为 on 时的文字描述String--
inactive-textswitch 的状态为 off 时的文字描述String--
active-valueswitch 状态为 on 时的值String--
inactive-valueswitch 状态为 off 时的值String--
nameinput 原生的 name 属性String--