其他分享
首页 > 其他分享> > 添加角色时 复选框默认选中某个值 并展示该值的数据

添加角色时 复选框默认选中某个值 并展示该值的数据

作者:互联网

选择角色的复选框组

              <el-checkbox-group
                v-model="checkedRoleGroupList"
                @change="checkedChangeRoleGroupHandler"
              >
                <el-checkbox
                  name="checked_RoleGroupList"
                  v-for="item in roleGroupList"
                  :key="`role_group_` + item.groupId"
                  :label="item.groupId"
                  :value="item.groupId"
                  >{{ item.groupName }}</el-checkbox
                >
              </el-checkbox-group>

点击事件

    async createRole() { //添加角色点击事件
     await this.getRoleGroupEnumAsync(); //调用复选框组 接口数据
      this.roleGroupList.forEach((item) => { //对列表数据进行过滤,
        if (item.groupName == "默认组") { //找到groupName是默认组的
          this.checkedRoleGroupList.push(item.groupId); //将他的grouId push 到 checkedRoleGroupList(这个是v-model绑定的数组)
          this.checkedChangeRoleGroupHandler([item.groupId]);//调用change事件,将item.groupId传进去,这样就展示该值的数据
        }
      });
    },

在这里插入图片描述

标签:groupName,默认,复选框,该值,选中,item,checkedRoleGroupList,groupId
来源: https://blog.csdn.net/Zheng_xinle/article/details/122807772