微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐