element-ui 中Switch的用法

简介: element-ui 中Switch的用法

在element-ui中,如果你想知道Switch是开还是关,使用事件 @change="getchange(value2)"


它会输出true或者false。true代表的是开,false代表的是关。


<template>
  <div>
    <el-switch
      v-model="value2"
      active-color="red"
      @change="getchange(value2)"
      inactive-color="#0033aa"
    ></el-switch>
    <div>{{obg.info}}</div>
    <el-button type="primary" @click="getclick">主要按钮</el-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      msg: "123",
      obg: {
        info: "12"
      },
      value2: true
    };
  },
  methods: {
    getchange(mess) {
      console.log(mess); //输出true或者false
      this.value2 = mess; //赋值
    },
    getclick() {
      console.log(this.value2);
      if (this.value2 && this.obg.info) { //这里使用的是&&运算 两个条件同时满足
        this.$message({
          message: "该同学已经有水卡",
          type: "success"
        });
      }
    }
  }
};
</script>
相关文章
|
4月前
|
搜索推荐 BI 开发者
sap.ui.comp.smarttable.SmartTable 组件 beforeRebindTable 事件的用法
sap.ui.comp.smarttable.SmartTable 组件 beforeRebindTable 事件的用法
|
JavaScript
element-ui(vue版)使用switch时change回调函数中的形参传值问题
element-ui(vue版)使用switch时change回调函数中的形参传值问题
132 0
|
4月前
|
算法 API 开发者
【Qt UI相关】Qt中如何控制 窗口的最大化、最小化和关闭按钮?一文带你掌握用法
【Qt UI相关】Qt中如何控制 窗口的最大化、最小化和关闭按钮?一文带你掌握用法
840 1
|
前端开发
前端项目实战玖拾伍react-admin+material ui-踩坑-List的用法之disableSyncWithLocation查询字符串同步
前端项目实战玖拾伍react-admin+material ui-踩坑-List的用法之disableSyncWithLocation查询字符串同步
57 0
|
前端开发
前端项目实战玖拾肆react-admin+material ui-踩坑-List的用法之disableAuthentication设置验证
前端项目实战玖拾肆react-admin+material ui-踩坑-List的用法之disableAuthentication设置验证
62 0
|
前端开发
前端项目实战玖拾叁react-admin+material ui-踩坑-List的用法之debounce设置显示时间
前端项目实战玖拾叁react-admin+material ui-踩坑-List的用法之debounce设置显示时间
68 0
|
10月前
element-ui和element-plus的自定义列表格用法
element-ui和element-plus的自定义列表格用法
68 0
|
11月前
|
Shell 容器
SAP UI5 的 Unified Shell 发展历史和用法介绍试读版
SAP UI5 的 Unified Shell 发展历史和用法介绍试读版
SAP UI5 的 Unified Shell 发展历史和用法介绍试读版
|
11月前
|
算法
sap.ui.comp.smarttable.SmartTable 一些属性的用法阐述
sap.ui.comp.smarttable.SmartTable 一些属性的用法阐述
|
11月前
【element-ui用法】el-radio-group默认选择和数据回显问题的解决方案
【element-ui用法】el-radio-group默认选择和数据回显问题的解决方案
572 0