• Vue 用checkbox实现两两组合多选且禁用第三个。


    本案例结合vant组件实现。思路是一样的。

    关键词:Vue-2,checkbox的disabled属性和change事件,v-if判断

    template:

    <van-checkbox-group v-model="isChe" @change="checkboxChange()">
              <van-checkbox name="0" :disabled="canChoose1">选项0</van-checkbox>
              <van-checkbox name="1" :disabled="canChoose2">选项1</van-checkbox>
              <van-checkbox name="2" :disabled="canChoose3">选项2</van-checkbox>
    </van-checkbox-group>
    
    <div v-if="show1">容器1</div>
    <div v-if="show2">容器2</div>
    <div v-if="show3">容器3</div>

    data:

    data(){
    
      return{ 
    
        isChe: [],
            canChoose1: false,
            canChoose2: false,
            canChoose3: false,
            show1: false,
            show2: false,
            show3: false,
      }
    
    }

    methods:

    checkboxChange() {
          console.log(this.isChe);
          if (this.isChe.indexOf("0") > -1) {
            this.show1 = true;
          } else {
            this.show1 = false;
          }
          if (this.isChe.indexOf("1") > -1) {
            this.canChoose3 = true;
            this.show2 = true;
          } else {
            this.canChoose3 = false;
            this.show2 = false;
          }
          if (this.isChe.indexOf("2") > -1) {
            this.canChoose2 = true;
            this.show3 = true;
          } else {
            this.show3 = false;
            this.canChoose2 = false;
          }
        },
  • 相关阅读:
    ASP连接mysql
    jsp中动态include与静态include的区别
    Create & Post free text invoice by code
    自定义Form作为Dialog
    动态多关联查询
    转到主表窗口
    获取当前用户组
    一个Job调用另外一个Job
    保存图片到硬盘
    在编辑框中增加右键菜单
  • 原文地址:https://www.cnblogs.com/jervy/p/13696671.html
Copyright © 2020-2023  润新知