在 Vue 2 的 Element UI 和 Vue 3 的 Element Plus 中,el-switch
(开关组件)提供了类似的属性和事件,但可能存在一些细微的差别或新增的功能。下面我将分别介绍 Vue 2 的 Element UI 和 Vue 3 的 Element Plus 中的 el-switch
组件的属性、事件和如何使用它们,并给出示例。
Vue 2 的 Element UI
el-switch
属性:
v-model
/value
:绑定值,true 为开,false 为关disabled
:是否禁用active-color
:开关打开时的背景色inactive-color
:开关关闭时的背景色active-text
:开关打开时的文字inactive-text
:开关关闭时的文字active-value
/inactive-value
:在表单中使用的值,分别对应打开和关闭状态的值,默认为 true/falsename
:原生属性 namevalidate-event
:是否触发表单的验证,默认为 truewidth
:开关的宽度(单位 px)
事件:
change
:开关状态变化时触发
方法