undefinedfix
Sign in

Vue checkbox select none select all

user618753 edited in Mon, 17 Oct 2022
 <el-col :span="24">
                  <el-form-item label="模块"></el-form-item>
                  <el-checkbox-group v-model="checkList_1">
                    <el-checkbox v-for="(item,index) in menu_module_1" :key="index" :label="index+1">{{item}}</el-checkbox>
                  </el-checkbox-group>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="方法"></el-form-item>
                  <el-checkbox-group v-model="checkList_2">
                    <el-checkbox v-for="(item,index) in menu_module_2" :key="index" :label="index+1">{{item}}</el-checkbox>
                  </el-checkbox-group>
                </el-col>

The checkbox list is obtained from the background. When you select the fourth one to fill in the data, select none of the following three. Select any of the following data to fill in, and cancel all to fill in

2 Replies
Smit
commented on Mon, 17 Oct 2022

After studying for a while, I don't talk much nonsense, I just go to the code

// 模块选择框响应事件
      handleMenuIds(val) {
        const index = val.indexOf(4);
        if (index === -1) {
          this.subitemIds = [];
          return;
        }
        if (this.subitemIds.length === 0 && index !== -1) {
          this.subitemIds = [1, 2, 3];
        }
      },
      // 方法选择框响应事件
      handleSubitemIds(val) {
        const index = this.menuIds.indexOf(4);
        // 如果方法没有选择项
        if (!val.length) {
          // 模块删除填报数据选项
          if (index !== -1) {
            this.menuIds.splice(index, 1);
          }
          return;
        }
        // 如果方法有选择项
        if (val.length) {
          // 模块增加数据选项
          if (index === -1) {
            this.menuIds.push(4);
          }
        }
      },
jcvwaugh
commented on Mon, 17 Oct 2022

The most convenient way is to add a @ change method to the checkbox, and then judge whether the data filled in is checked when the change is triggered. If so, put the checklist_ 2, check list_ Is at least one of 2 checked? If so, the data to be filled in will be selected