vue2.0 实现全选和全不选
发布时间:2020-12-16 23:15:02 所属栏目:百科 来源:网络整理
导读:h3 id="实现思路"实现思路: 1、 v-model 一个收集所有input(除全选框外)数组checkModel ,vue会动态将其checked为true的input的value值存入数组checkModel里 2 、watch函数来监听checkModel 属性,当其长度==input元素时 全选按钮选中 否则取消 3 、全选
<h3 id="实现思路">实现思路: 1、 v-model 一个收集所有input(除全选框外)数组checkModel ,vue会动态将其checked为true的input的value值存入数组checkModel里 2 、watch函数来监听checkModel 属性,当其长度==input元素时 全选按钮选中 否则取消 3 、全选按钮v-model checked 属性来显示当前选中状态 click事件里 当checked为true时 全选 所有input按钮被选中也就是checkModel的遍历存入其value值
全选
data(){ return { list:[ {id:1,name:"明明",age:23,money:100}, {id:2,name:"红红",age:18,money:200}, {id:3,name:"强强",age:29,money:300} ], checked:false,//是否全选 checkModel:[] //双向数据绑定的数组,我是用的id } },watch:{ checkModel(){ if(this.checkModel.length==this.list.length){ this.checked=true; }else{ this.checked=false; } } },methods:{ checkAll(){ if(this.checked){ this.checkModel=[]; }else{ this.list.forEach((item)=>{ if(this.checkModel.indexOf(item.id)==-1){ this.checkModel.push(item.id) } }) } } }
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- ruby-on-rails – Devise with Confirmable – 当
- 在Flash build中添加Android SDK
- 一个封装好的CSV文件操作C#类代码
- Actionscript3 / Flex中的HTML特殊实体代码
- Solr索引库l配置文件schema.xml讲解
- 如何在PostgreSQL中声明一个变量
- c# – WPF Datagrid – 不显示任何滚动条
- ruby-on-rails – 乘客错误:应用程序spawner服务
- Need to add a category for addStratosphereSsp
- Oracle JOIN USING子查询:ora-00904字符串:无效
热点阅读