<template>
<div>
<div class="xuanze">
<label><input type="checkbox" v-model="all" @change="allfn">全选</label> <br><br> <div class="store" v-for="(store,index1) in stores">
<label><input type="checkbox" v-model="store.all" @change="storefn(index1)">{{store.name}}</label>
<ul>
<li v-for="(item,index2) in store.product"><label><input type="checkbox" v-model="item.xuanze" @change="productfn(index1,index2)">{{item.id}}</label></li>
</ul>
</div>
</div>
</div>
</template> <script>
export default {
data () {
return {
all: false, stores: [
{
name: '草泥马一号店',
all: false,
sellength: 0,
product:[
{
id: 1,
xuanze: false,
},
{
id: 2,
xuanze: false,
},
{
id: 3,
xuanze: false,
},
]
},
{
name: '草泥马二号店',
all: false,
sellength: 0,
product:[
{
id: 1,
xuanze: false,
},
{
id: 2,
xuanze: false,
},
{
id: 3,
xuanze: false,
},
]
},
]
}
},
methods: {
allfn: function(){
for (let i = 0;i < this.stores.length ;i++ )
{
let store = this.stores[i];
store.sellength = this.all ? store.product.length : 0;
store.all = this.all;
for (let j = 0;j < store.product.length ;j++ )
{
store.product[j].xuanze = this.all;
}
}
},
storefn: function(index1){
let store = this.stores[index1];
let res = store.all;
store.sellength = res ? store.product.length : 0;
for (let i = 0;i < store.product.length ;i++ )
{
store.product[i].xuanze = res;
}
this.all = true;
for (let j = 0;j < this.stores.length ;j++ )
{
if (!this.stores[j].all)
{
this.all = false;
break;
}
}
},
productfn: function(index1,index2){
let store = this.stores[index1];
let product = store.product[index2];
store.sellength = product.xuanze ? store.sellength+1:store.sellength-1;
store.all = store.sellength == store.product.length;
this.all = true;
for (let j = 0;j < this.stores.length ;j++ )
{
if (!this.stores[j].all)
{
this.all = false;
break;
}
}
}
}
}
</script> <style scoped>
.xuanze{
margin: 100px;
}
.store{
border-bottom: 1px solid red;
margin-bottom: 5px;
}
ul{
margin-left: 20px;
}
</style>

  

vue全选反选demo的更多相关文章

  1. Vue 全选/取消全选,反选/取消反选

    这是一个组件: <template> <div> <div> <input type="checkbox" v-model="i ...

  2. jquery实现全选/反选功能

    <!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...

  3. 全选,反选,获取值ajax提交

    //必须先加载jquery //加载 弹出框插件 artdialog http://www.planeart.cn/demo/artDialog/ /****全选反选*开始**/ $(document ...

  4. JavaScript、全选反选-课堂笔记

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 关于input全选反选恶心的异常情况

    上一篇讲到:第一次点击全选按钮input显示对勾,第二次则不显示,需要用prop来添加checked属性. 但是用prop会出现一个问题,对勾显示,而checked属性不会被添加(比如:$(" ...

  6. jQuery全选/反选checkbox

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. python: jquery实现全选 反选 取消

    引入这个jquery-1.12.4.js jquery实现全选 反选 取消 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitio ...

  8. BootStrapt iCheck表单美化插件使用方法详解(含参数、事件等) 全选 反选

    特色: 1.在不同浏览器(包括ie6+)和设备上都有相同的表现 — 包括 桌面和移动设备 2.支持触摸设备 — iOS.Android.BlackBerry.Windows Phone等系统 4.方便 ...

  9. 用javascript实现全选/反选组件

    以下是本人制作的全选/反选 组件,供广大同行参考.指正: 效果如图: 在实现的过程中,全选和全部取消选中这两个功能较为简单,只需用for循环遍历所有复选框为true或false即可.反选也较为简单,也 ...

随机推荐

  1. 1.3浅谈Spring(IOC容器的实现)

    这一节我们来讨论IOC容器到底做了什么. 还是借用之前的那段代码 ClassPathXmlApplicationContext app = new ClassPathXmlApplicationCon ...

  2. saltstack主机管理项目:动态调用插件解析-模块解析(五)

    一.动态调用插件解析 1.目录结构 1.base_module代码解析: def syntax_parser(self,section_name,mod_name,mod_data): print(& ...

  3. java调用matlab绘图

    一 注意事项 1: MatLab的版本必须是2006b+(包括2006b或更高版本),因为只有在这些版本中才有MATLAB Builder for Java(也叫Java Builder). 2: 运 ...

  4. HTML/CSS: 如何制作未读信息图标

    最近公司项目中涉及到制作通讯界面中未读信息的带数字的红色圆点图标. 拿我目前的博客头像图片为例(其实就是谷歌图片中粗略挑了一张顺眼的图片),效果图如下: HTML代码如下: <img id=&q ...

  5. tex中pdf外链

    \documentclass{article} \usepackage{hyperref} \begin{document} \href{run:d:/my folder/test.pdf}{This ...

  6. Regularity criteria for NSE 5: $u_3,\om_3$

    In [Zhang, Zujin. Serrin-type regularity criterion for the Navier-Stokes equations involving one vel ...

  7. sonarqube6.7部署文档

    应用介绍:sonarqube是一个用于代码质量管理的开源平台,用于管理源代码的质量通过插件形式:可以支持包括Java.C#/C++.PL/SQL.Cobol.javascrip.Groovy等等二十几 ...

  8. MySQL学习9 - 单表查询

    一.单表查询的语法 二.关键字的执行优先级(重点) 三.单表查询示例 1.where约束 2.group by分组查询 3.聚合函数 4.HAVING过滤 5.order by查询排序 6.limit ...

  9. 第三章 Java的基础程序设计结构

    一个简单的 Java 应用程序 访问修饰符 public,private,protected main 方法必须时public修饰的,C#则不必须 数据类型 可以用16进制表示浮点数 可以用2,8,1 ...

  10. JavaWeb - Apache与Tomcat有什么关系和区别

    总结: 1- apache是web服务器,侧重于http server: tomcat是应用(java)服务器,侧重于servlet引擎 2-合作过程详解,请看:JavaWeb - apache和to ...