Skip to content

Switch 开关

通常用于切换开启和关闭状态。

按需引入方式

如果是完整引入可跳过此步骤

javascript
import Vue from 'vue'
import { Switch } from 'element-ui'
import 'element-ui/lib/theme-chalk/base.css'
import 'element-ui/lib/theme-chalk/switch.css'

Vue.use(Switch)
import Vue from 'vue'
import { Switch } from 'element-ui'
import 'element-ui/lib/theme-chalk/base.css'
import 'element-ui/lib/theme-chalk/switch.css'

Vue.use(Switch)

基础用法

vue
<template>
    <el-switch v-model="value" active-color="#10b981" inactive-color="#424243"> </el-switch>
</template>

<script>
export default {
    data() {
        return {
            value: true
        }
    }
}
</script>
<template>
    <el-switch v-model="value" active-color="#10b981" inactive-color="#424243"> </el-switch>
</template>

<script>
export default {
    data() {
        return {
            value: true
        }
    }
}
</script>

Attributes

参数说明类型默认值
v-model选中项绑定值boolean | string | number
active-color打开时的背景色string#409EFF
inactive-color关闭时的背景色string#C0CCDA
...