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