vue效果之改element的el-checkbox-group多选框组为单选可取消的单选框(样式还是多选框的样式)

摘要:
Vue˂el checkboxxv for=“(项目,索引)subjectList”@change=“clickThematicMapItem(项目,指数)”:key=“item.menu”:label=“item.maenu”=disabled=“item.mmenu=='责任区'

vue

vue效果之改element的el-checkbox-group多选框组为单选可取消的单选框(样式还是多选框的样式)第1张

<el-checkbox-group v-model="listThematicChecked">
        <el-checkbox v-for="(item , index) in subjectList" @change="clickThematicMapItem(item,index)" :key="item.menu" :label="item.menu" :disabled="item.menu === '责任区' && disabledZeRenQu">
          <img :src="http://t.zoukankan.com/item.img" alt="" />&nbsp;&nbsp;{{ item.menu }}
          <em   v-show="item.menu == '辖区态势图' || item.menu == '四色预警图'" @click.prevent="fourClick(item)">...</em>
        </el-checkbox>
      </el-checkbox-group>

data里的数据

vue效果之改element的el-checkbox-group多选框组为单选可取消的单选框(样式还是多选框的样式)第2张vue效果之改element的el-checkbox-group多选框组为单选可取消的单选框(样式还是多选框的样式)第3张
listThematicChecked: [],
subjectList: [
        {
          menu: '辖区态势图',
          img: '/static/images/icon-tuli/tuli_xiaqutaishitu_icon.png',
          isCheck: false,
          fourMoreEm: false,
          isqx: 0,
          type: 'taishitu'
        },
        {
          menu: '警力热力图',
          img: '/static/images/icon-tuli/tuli_relitu_icon.png',
          isCheck: false,
          isqx: 0,
          type: 'relitu'
        },
        {
          menu: '警情热力图',
          img: '/static/images/icon-tuli/tuli_relitu_icon.png',
          isCheck: false,
          isqx: 0,
          type: 'jingqingtu'
        },
        {
          menu: '四色预警图',
          img: '/static/images/icon-tuli/tuli_siseyujingtu_icon.png',
          isCheck: false,
          fourMoreEm: false, //4色预警后三个点
          isqx: 0,
          type: 'sisetu'
        },
        {
          menu: '警情统计图',
          img: '/static/images/icon-tuli/tuli_jingqingtongji_icon.png',
          isCheck: false,
          isqx: 0,
          type: 'tongjitu'
        }
      ],
View Code
vue效果之改element的el-checkbox-group多选框组为单选可取消的单选框(样式还是多选框的样式)第4张vue效果之改element的el-checkbox-group多选框组为单选可取消的单选框(样式还是多选框的样式)第5张
clickThematicMapItem(item, index) {
      console.log('367', item);
      //把多选做成单选的样式
      let check = null;
      this.subjectList.forEach(res => {
        if (res.menu == item.menu) {
          res.isCheck = true;
          res.isqx += 1;
          //2为同一个的取消,1为同一个的选中
          if (res.isqx == 2) {
            res.isqx = 0;
            check = false;
          } else if (res.isqx == 1) {
            check = true;
          }
        } else {
          res.isCheck = false;
          res.isqx = 0;
        }
      });
      let cname = item.menu;
      console.log('387', this.listThematicChecked);
      //return;
      let nList = this.listThematicChecked.filter(word => word == cname);
      this.listThematicChecked = nList;
      console.log('389', this.listThematicChecked);//过滤成当前勾选框只能勾选一个
      this.$parent.leftNavType = '';
      this.leftCloseDio();
      switch (item.type) {
        //辖区态势
        case 'taishitu':
          if (check) {
            this.$parent.$refs.dsMap.clearTrailLine();
            this.$parent.$refs.dsMap.readTsFeatures(tsData, 'taishitu');
            this.$parent.$refs.dsMap.clearFeatures('tongjitu');
            this.$parent.$refs.dsMap.clearFeatures('sisetu');
            this.$parent.$refs.dsMap.clearHotFeatures('relitu');
            this.$parent.$refs.dsMap.clearHotFeatures('jingqingtu');
          } else {
            this.$parent.$refs.dsMap.clearFeatures('taishitu');
          }
          break;
        //警力热力
        case 'relitu':
          if (check) {
            this.$parent.$refs.dsMap.clearTrailLine();
            this.$parent.$refs.dsMap.readJqHotFeatures('relitu');
            this.$parent.$refs.dsMap.clearFeatures('taishitu');
            this.$parent.$refs.dsMap.clearFeatures('tongjitu');
            this.$parent.$refs.dsMap.clearFeatures('sisetu');
            this.$parent.$refs.dsMap.clearHotFeatures('jingqingtu');
          } else {
            this.$parent.$refs.dsMap.clearHotFeatures('relitu');
          }
          break;

        //警情热力
        case 'jingqingtu':
          if (check) {
            // this.$parent.leftNavType = '';
            // this.leftCloseDio();
            this.$parent.$refs.dsMap.clearTrailLine();
            this.$parent.$refs.dsMap.readJqHotFeatures('jingqingtu');
            this.$parent.$refs.dsMap.clearFeatures('taishitu');
            this.$parent.$refs.dsMap.clearFeatures('tongjitu');
            this.$parent.$refs.dsMap.clearFeatures('sisetu');
            this.$parent.$refs.dsMap.clearHotFeatures('relitu');
          } else {
            this.$parent.$refs.dsMap.clearHotFeatures('jingqingtu');
          }
          break;
        //预警统计态势
        case 'tongjitu':
          if (check) {
            this.$parent.$refs.dsMap.clearTrailLine();
            this.$parent.$refs.dsMap.readTsFeatures(tsData, 'tongjitu');
            this.$parent.$refs.dsMap.clearFeatures('taishitu');
            this.$parent.$refs.dsMap.clearFeatures('sisetu');
            this.$parent.$refs.dsMap.clearHotFeatures('relitu');
            this.$parent.$refs.dsMap.clearHotFeatures('jingqingtu');
          } else {
            this.$parent.$refs.dsMap.clearFeatures('tongjitu');
          }
          break;
        //四色
        case 'sisetu':
          if (check) {
            this.$parent.$refs.dsMap.clearTrailLine();
            this.$parent.$refs.dsMap.readTsFeatures(tsData, 'sisetu');
            this.$parent.$refs.dsMap.clearFeatures('taishitu');
            this.$parent.$refs.dsMap.clearFeatures('tongjitu');
            this.$parent.$refs.dsMap.clearHotFeatures('relitu');
            this.$parent.$refs.dsMap.clearHotFeatures('jingqingtu');
          } else {
            this.$parent.$refs.dsMap.clearFeatures('sisetu');
          }
          break;
      }
    },
View Code

vue效果之改element的el-checkbox-group多选框组为单选可取消的单选框(样式还是多选框的样式)第6张

后面...的点击效果,如果当前为勾选状态,点击...为切换另外一种区域图,再点击就是切换到勾选的那个区域图

vue效果之改element的el-checkbox-group多选框组为单选可取消的单选框(样式还是多选框的样式)第7张vue效果之改element的el-checkbox-group多选框组为单选可取消的单选框(样式还是多选框的样式)第8张
  fourClick(data, fourMoreEm) {
      console.log('259', this.subjectList);
      if (data.isCheck === true) {
        console.log(data);
        switch (data.type) {
          //辖区态势
          case 'taishitu':
            this.$parent.$refs.dsMap.clearTrailLine();
            this.$parent.$refs.dsMap.clearFeatures('taishitu');
            // this.subjectList[3].isCheck = false;
            // this.subjectList[0].isCheck = true;
            if (data.fourMoreEm === false) {
              this.$parent.$refs.dsMap.readTsFeatures(allData, 'taishitu');
            } else {
              this.$parent.$refs.dsMap.readTsFeatures(tsData, 'taishitu');
            }
            this.$parent.$refs.dsMap.clearFeatures('tongjitu');
            this.$parent.$refs.dsMap.clearFeatures('sisetu');
            this.$parent.$refs.dsMap.clearHotFeatures('relitu');
            this.$parent.$refs.dsMap.clearHotFeatures('jingqingtu');

            break;
          //四色
          case 'sisetu':
            this.$parent.$refs.dsMap.clearTrailLine();
            this.$parent.$refs.dsMap.clearFeatures('sisetu');
            // this.subjectList[0].isCheck = false;
            // this.subjectList[3].isCheck = true;
            if (data.fourMoreEm === false) {
              this.$parent.$refs.dsMap.readTsFeatures(allData, 'sisetu');
            } else {
              this.$parent.$refs.dsMap.readTsFeatures(tsData, 'sisetu');
            }
            this.$parent.$refs.dsMap.clearFeatures('taishitu');
            this.$parent.$refs.dsMap.clearFeatures('tongjitu');
            this.$parent.$refs.dsMap.clearHotFeatures('relitu');
            this.$parent.$refs.dsMap.clearHotFeatures('jingqingtu');
            break;
        }
        data.fourMoreEm = !data.fourMoreEm;
      } else {
        console.log('我是f');
      }
    },
View Code

思路解析:

点击多选组件,

1>当前点击的这个对象和整个原始list去匹配,如果相同则让当前计数器isqx 加1,以及状态isCheck为true代表被选中;否则就是else里面的;

2>当相同的一个再点击一次,代表的是这个多选取消的效果,这个时候,计数器isqx加了1后就是2;然后走进判断

if (res.isqx == 2) {
            res.isqx = 0;
            check = false;
          } else if (res.isqx == 1) {
            check = true;
          }
然后用check去判断到底是取消还是选上的状态;

免责声明:文章转载自《vue效果之改element的el-checkbox-group多选框组为单选可取消的单选框(样式还是多选框的样式)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇若依管理系统源码分析-分页的实现以及post请求时的分页在docker容器中访问宿主机端口下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

vue-构建app项目

以下记录vue-cli 3构建app项目的步骤。 一、初始化配置,并运行启动app 1、安装nodeJS,git ,配置环境,Vue CLI 3.x 需要 Node.js 8.9 或更高版本 (推荐 8.11.0+)。 2、安装vue-cli ,命令:npm install -g @vue/cli 3、创建项目:vue create mapp-demo 推...

在Vue中使用了Swiper ,从后台获取动态数据后,swiper滑动失效

原因是因为Swiper提前初始化了,然而数据还没有加载完成。解决方法如下: 1、在Swiper初始化时 swiper0 = new Swiper('.w0', { initialSlide :0, observer:true,//修改swiper自己或子元素时,自动初始化swiper observeParents:true,//修改...

Python+Selenium笔记(十五)调用JS

(一)方法 方法 简单说明 execute_async_script(script, args) 异步执行JS代码 script:被执行的JS代码 args:js代码中的任意参数 execute_script(script, args) 同步执行JS代码 script:被执行的JS代码 args:js代码中的任意参数 (二)示例 f...

零基础 Vue 开发环境搭建 打开运行Vue项目

【相关推荐】IntellIJ IDEA 配置 Vue 支持 打开Vue项目 所需文件 node.js环境(npm包管理器)(node-v8.11.3-x64.msi)(npmV5.6.0) cnpm npm的淘宝镜像 vue-cli 构建工具(脚手架) 一、安装node 安装完node,就自动在path里增加环境变量,但是为了以后的本地部署项目,我们需要找...

VS Code中Vetur与prettier、ESLint联合使用

一、vue语法高亮1.1 安装Vetur 1. 创建.vue文件, 写些代码, 发现一片漆黑 2. 安装激活vetur插件, 代码就有高亮了. 右键菜单还会变多一些, 主要多了个格式化文档.   这里配置了多个格式化的,所以会有多个。 看下vetur的特性: 语法高亮, 代码片段(emmet给我的感觉是一个写好了的snippet), 质量提示&...

Vue数据可视化组件:DataV

组件库名称:DataV 项目地址:https://github.com/DataV-Team/DataV 文档地址 贴几个Demo图 DataV是一个基于Vue数据可视化组件库,类阿里DataV,提供SVG的边框及装饰,图表,飞线图等组件,简单易用。 主要的组件类型 SVG的边框,主要用于提升页面效果,一个边框组件仅几k到十几k,后期会添加颜色之类的配置...