<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. 【Sql Server】SQL SERVER 收缩日志

    事务日志记录着在相关数据库上的操作,同时还存储数据库恢复(recovery)的相关信息. 收缩日志的原因有很多种,有些是考虑空间不足,有些则是应用程序限制导致的. 下面介绍的是在简单模式下,进行收缩操 ...

  2. 金融量化分析【day112】:均值回归策略

    一.均值回归策略 1.什么是回归策略 二.归一标准化 import numpy as np a = np.random.uniform(100,5000,1000) b = np.random.uni ...

  3. CCPC-Wannafly Winter Camp Day5 (Div2, onsite) Sorting(线段树)

    题目链接 题意 对序列进行三种操作: 1.区间求和. 2.将区间小于等于$x$的数不改变相对顺序的前提下放到$x$左边,用同样规则将比$x$大的放到右边. 3.将区间大于$x$的数不改变相对顺序的前提 ...

  4. 清北学堂学习总结day1

    上午篇 一.高精度计算: [以下内容先只考虑非负数情况] •高精度加法: 思路:[模拟竖式运算] 注意:[进位] •高精度减法: 思路:[同加法类似,模拟竖式运算,进位变退位] 注意: [结果为负数的 ...

  5. FTP:mget匹配文件名后下载

    需求:从FTP某目录取每日构建的apk下载到本地 难点:文件名中有构建时间,而这个时间不算固定值,因此文件名不固定 解决方案:mget匹配文件名后下载 BAT版本: :: Filename:Proje ...

  6. tarjan 题目汇总(含解析)

    下面容许我偷个懒,洛谷上写过的blog我就不来再抄一遍了 洛谷P3436 [[POI2006]PRO-Professor Szu](别称:作死的老教授) 洛谷P4306 [[JSOI2010]连通数] ...

  7. 【MYSQL】MYSQL报错解决方法: Warning: (3719, "'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8M B4 in a future release."

    用python3.6.5创建mysql库时出现如下报错,虽然报错,但是数据库可以插入成功. D:\python3\lib\site-packages\pymysql\cursors.py:170: W ...

  8. iOS 推荐几篇关于Objective-c 动态语言的文章

    http://www.cnblogs.com/Mr-Lin/p/5771969.html https://onevcat.com/2012/04/objective-c-runtime/ 我摘抄几句比 ...

  9. nginx——location匹配流程图

    location匹配流程图 location理解 1.收到url请求后,nginx首先进行精确匹配(有“=”的为精确匹配),如果匹配成功,则直接返回精确匹配结果,如果没有命中则会继续向下进行普通匹配 ...

  10. Javascript我学之三函数的参数

    本文是金旭亮老师网易云课堂的课程笔记,记录下来,以供备忘 函数的参数             对于参数值,JavaScript不会进行类型检查,任何类型的值都可以被传递给参数.             ...