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

基本用法

绑定v-model到一个Boolean类型的变量。可以使用active-color属性与inactive-color属性来设置开关的背景色。

 <el-switch
v-model="value2"
active-color="#13ce66"
inactive-color="#ff4949">
</el-switch> <script>
export default {
data() {
return {
value1: true,
value2: true
}
}
};
</script>

文字描述

使用active-text属性与inactive-text属性来设置开关的文字描述。

<el-switch
v-model="value3"
active-text="按月付费"
inactive-text="按年付费">
</el-switch>
<el-switch
style="display: block"
v-model="value4"
active-color="#13ce66"
inactive-color="#ff4949"
active-text="按月付费"
inactive-text="按年付费">
</el-switch> <script>
export default {
data() {
return {
value3: true,
value4: true
}
}
};
</script>

扩展的 value 类型

设置active-valueinactive-value属性,接受BooleanStringNumber类型的值。

 <el-tooltip :content="'Switch value: ' + value5" placement="top">
<el-switch
v-model="value5"
active-color="#13ce66"
inactive-color="#ff4949"
active-value="100"
inactive-value="0">
</el-switch>
</el-tooltip> <script>
export default {
data() {
return {
value5: '100'
}
}
};
</script>

禁用状态

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

 <el-switch
v-model="value6"
disabled>
</el-switch>
<el-switch
v-model="value7"
disabled>
</el-switch>
<script>
export default {
data() {
return {
value6: true,
value7: false
}
}
};
</script>

Attributes

参数 说明 类型 可选值 默认值
disabled 是否禁用 boolean false
width switch 的宽度(像素) number 40
active-icon-class switch 打开时所显示图标的类名,设置此项会忽略 active-text string
inactive-icon-class switch 关闭时所显示图标的类名,设置此项会忽略 inactive-text string
active-text switch 打开时的文字描述 string
inactive-text switch 关闭时的文字描述 string
active-value switch 打开时的值 boolean / string / number true
inactive-value switch 关闭时的值 boolean / string / number false
active-color switch 打开时的背景色 string #409EFF
inactive-color switch 关闭时的背景色 string #C0CCDA
name switch 对应的 name 属性 string

Events

事件名称 说明 回调参数
change switch 状态发生变化时的回调函数 新状态的值

Methods

方法名 说明 参数
focus 使 Switch 获取焦点 -

Switch 开关的更多相关文章

  1. 自定义switch开关

    自定义一个switch开关 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  2. mui的switch开关的应用

    HTML: <!--mui的switch开关--> <div class="mui-content-padded"> <h5>switch开关m ...

  3. CSS做一个Switch开关

    本文为博主原创,转载请注明出处. Switch开关: 根据需求可知,Switch开关只有两种选择,true或false.所以我们想到HTML的checkbox控件,用它来做. <input id ...

  4. 使用css3 制作switch开关

    使用css3来实现switch开关的效果: html代码: <!--switch开关--><div class="switch-btn"> <inpu ...

  5. 微信小程序组件解读和分析:十五、switch 开关选择器

    switch 开关选择器组件说明: switch,开关选择器.只能选择或者不选.这种属于表单控件或者查询条件控件. switch 开关选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯 ...

  6. elementui switch 开关,点击确认按钮后在进行开关

    <el-table-column label="上头条" align="center"> <template slot-scope=" ...

  7. 微信小程序 主题皮肤切换(switch开关)

    示例效果: 功能点分析: 1.点击switch开关,切换主题皮肤(包括标题栏.底部tabBar):2.把皮肤设置保存到全局变量,在访问其它页面时也能有效果3.把设置保存到本地,退出应用再进来时,依然加 ...

  8. mui switch(开关)里面token不能及时更新

    做登录的时候再本地用locaStorage存了一个token值,但是登录之后进入页面里面发现一个switch开关里面的token值会跟着开关的切换在上一个token和当前的这个token值之间切换,我 ...

  9. layui switch 开关监听 弹出确定状态转换

    不废话,直接上图: 原始状态:   点击确定: 点击取消或者X 代码: <!doctype html> <html lang="en"> <head& ...

  10. mui switch 开关js控制打开 & Cannot read property 'toggle' of null

    //打开开关 mui('#mySwitch').switch().toggle(); //小开关打开异常的情况解决办法$(".mui-switch-handle").attr(&q ...

随机推荐

  1. C# 文件操作的一些小点子

    1. 判断指定文件是否存在: bool System.IO.File.Exits(string fliePath);

  2. Java定时任务的几种方法(Thread 和 Timer,线程池)

    /** * 普通thread * 这是最常见的,创建一个thread,然后让它在while循环里一直运行着, * 通过sleep方法来达到定时任务的效果.这样可以快速简单的实现,代码如下: * */ ...

  3. JS转为number的四种方法

    // 1.Number() var num1 = Number(true); console.log(num1); var num2 = Number(" ") console.l ...

  4. ESXi与物理交换机静态链路聚合配置过程中的小陷阱

    作者:陆斌文章来自微信公众号:平台人生 内容简介:ESXi与物理交换机之间配置静态链路聚合时,因为静态链路聚合的特点,在进行down网卡和从虚拟交换机移除网卡的操作时,可能会无法完成故障流量切换,影响 ...

  5. ES修改最大分页数

    curl -XPUT http://localhost:9200/my_index/_settings?preserve_existing=true -H 'Content-Type: applica ...

  6. supervisor部署tornado

    supervisord常见命令 supervisorctl shutdown 关闭命令 supervisord -c /etc/supervisord.conf 启动supervisord super ...

  7. DevExpress实现为TextEdit设置水印文字的方法

    设置水印与消除水印 public static void SetWatermark(TextEdit textEdit, string watermark) { textEdit.Properties ...

  8. 动软生成器 model生成模板

    <#@ template language="c#" HostSpecific="True" #> <#@ output extension= ...

  9. 手动编译源码安装包报错 fatal error:cruses.h: no such file or direcrory

    很明显是缺少cruses.h这个文件,但是用yum搜索又搜不到,可能是我的yum源的库包太少的原因吧. 后来多方查找,发现cruses.h这个头文件属于ncurses模块,需要安装ncurses-de ...

  10. python连接mysql操作(1)

    python连接mysql操作(1) import pymysql import pymysql.cursors # 连接数据库 connect = pymysql.Connect( host='10 ...