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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM