<!--包含  全选/不全选   批量删除   全部金额计算   数量加减-->

简陋的CSS代码

.main{
width: 100%;
}
.title{
width: 100%;
height: 40px;
line-height: 40px;
background: #4c4c4c;
color: #ffffff;
}
.title input{
width: 20px;
height:20px;
background: #ffffff;
margin-left: 20px;
appearance: checkbox;
-webkit-appearance: checkbox;
}
.list_item input{ width: 20px;
height:20px;
appearance: checkbox;
-webkit-appearance: checkbox;
}
ul{
width: 100%;
}
li.list_item{
width: 100%;
height: 100px;
border-bottom: 4px solid blue;
padding: 4px;
}
li.list_item .L{
width: 20%;
height: 100%;
}
li.list_item .L img{
width: 100%;
height: 100%;
}
li.list_item .R{
width: 80%;
height: 100%;
}
.jian,.jia{
display: inline-block;
width: 40px;
height: 40px;
line-height: 40px;
text-align: center;
background: black;
color: #ffffff;
} HTML代码
<div class="main">
<div class="title">
<input type="checkbox" name="vehicle1" value="Bike" @click="quan" v-model="quanTodo">全选/不全选
<span class="fr" @click="deleteTodo">批量删除</span>
</div>
<ul class="list">
<li class="list_item" v-for="(item,index) in list">
<div class="L fl">
<img src="../img/timg1.jpg">
</div>
<div class="R fl">
<h1>{{item.title}}</h1>
<div class="compute">
<span class="price"></span>
<div class="compute_R">
<span class="jian" @click="jian(item)">-</span>
<span class="num">{{item.num}}</span>
<span class="jia" @click="add(item)">+</span>
</div>
<input type="checkbox" name="vehicle" :checked="item.checkbox" v-model="item.checkbox">
</div>
</div>
</li>
</ul>
共计{{reversedMessage}}元
</div> JS代码
let arr=[
{title:'商品1',num:1,price:10,checkbox:true},
{title:'商品2',num:1,price:20,checkbox:true},
{title:'商品3',num:1,price:30,checkbox:true},
{title:'商品4',num:1,price:40,checkbox:true}
];
var vm=new Vue({
el:".main",
data:{
list:arr,
quanTodo:true
},
computed: {
reversedMessage: function () {
var price=0;
for(var i=0;i<this.list.length;i++){
if(this.list[i].checkbox){
price+=this.list[i].num*this.list[i].price;
}
}
return price;
}
},
methods:{
a(item){
console.log(item);
},
jian(item){
if(item.num>0){
item.num--;
} },
add(item){
item.num++;
},
quan(){
console.log(this.quanTodo);
if(this.quanTodo==true){
for(var i=0;i<this.list.length;i++){
this.list[i].checkbox=false;
}
console.log('不选中'+this.quanTodo);
}
else{
console.log('选中'+this.quanTodo);
console.log(this.list);
for(var j=0;j<this.list.length;j++){
this.list[j].checkbox=true;
console.log(this.list[j].checkbox);
}
}
},
deleteTodo(){
for(var i=this.list.length-1;i>=0;i--){
if(this.list[i].checkbox){
var index=this.list.indexOf(this.list[i]);
this.list.splice(index,1);
}
}
}
}
});

  

Vue实现商城里面多个商品计算,全选,删除的更多相关文章

  1. vue实现商品购物车全选与全不选项目实战

    项目需求: 实现一个购物车 全选框实现对商家和商品的全选 商家全选框实现对当前商家所有商品的全选 取消其中一个商品则取消对应商家全选和全选框 选中一个商家下的所有商品则勾选对应商家的全选框,不勾选全选 ...

  2. vue实战记录(五)- vue实现购物车功能之商品总金额计算和单选全选删除功能

    vue实战,一步步实现vue购物车功能的过程记录,课程与素材来自慕课网,自己搭建了express本地服务器来请求数据 作者:狐狸家的鱼 本文链接:vue实战-实现购物车功能(五) GitHub:sue ...

  3. vue2购物车ch3-(过滤器使用 单件商品金额计算 全选全不选 总金额计算 删除商品功能)

    1 index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  4. vue实现全选效果

    vue实现全选效果 接触vue快半年了,记得刚用vue做项目的时候遇到一个全选功能,当时到处百度也没有找到怎么实现,最后还是用了jquery进行dom操作实现的. 今天没事就顺手写了一个,感觉很简单, ...

  5. vue中实现全选功能

    <!DOCTYPE html><html><head><meta charset="utf-8"><title>Vue ...

  6. Vue全选和全不选

    HTML代码: <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script> ...

  7. vue+vant-UI框架写的购物车的复选框全选和反选

    购物车页面的设计图 商品的列表 代码: <ul v-if="shoppingListData.rows.length"> <li v-for="(ite ...

  8. thinkphp5+vue+iview商城 公众号+小程序更新版本

    thinkphp5+vue+iview商城加分销 源码下载地址:http://github.crmeb.net/u/crmeb 演示站后台:http://demo25.crmeb.net 账号:dem ...

  9. 基于vue2.0打造移动商城页面实践 vue实现商城购物车功能 基于Vue、Vuex、Vue-router实现的购物商城(原生切换动画)效果

    基于vue2.0打造移动商城页面实践 地址:https://www.jianshu.com/p/2129bc4d40e9 vue实现商城购物车功能 地址:http://www.jb51.net/art ...

随机推荐

  1. c# DateTime 类

    获得当前系统时间: DateTime dt = DateTime.Now;Environment.TickCount可以得到"系统启动到现在"的毫秒值DateTime now = ...

  2. 最近一直在做java爬虫,有些感悟心得,分享给大家;

    首先,看完这篇文章,不能保证你成为大神,但是却可以让你懂得什么是爬虫,如何使用爬虫,如何利用http协议,侵入别人的系统,当然只是一些简单的教程,拿到一些简单的数据: 先上代码,在一步一步讲解: 这是 ...

  3. 【Alpha】第二次Daily Scrum Meeting

    GIT 一.今日站立式会议照片 二.会议内容 1.统计,收集整理礼物的资料与详情 2.确定网页的实现方式 三.燃尽图

  4. 201521123096《Java程序设计》第六周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 2. 书面作业 (1)clone方法 1.1 Object ...

  5. 201521123070 《JAVA程序设计》第9周学习总结

    1. 本章学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 Q1. 常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 ...

  6. 设置文件opendilag、savedilog默认路径和文件类型

    dlgSave1.Filter:='文件.txt|*.txt;|word文件|*.doc,*.docx'; dlgSave1.InitialDir:=GetCurrentDir; //设置为当前路径 ...

  7. 二分求最长上升子序列 二分LIS

    #include <iostream> #include <cstring> #define N 50010 using namespace std; int n; int n ...

  8. 移动商城第三篇【搭建Mybatis和Spring环境、编写Dao、Service在Core模块】

    Mybatis和Spring环境搭建 由于我们的所编写的dao层.service代码可能前台和后台都需要用到的,因此我们把环境搭建在core模块中 逆向工程 首先,我们要做的就是品牌管理,我们首先来看 ...

  9. spring的一些问题

    1.什么是spring? spring是一个轻量级的一站式框架,它的核心有两个部分,1.aop面向切面编程 2.ioc控制反转. 2.什么是aop aop就是面向切面编程,使用aop可以使业务逻辑各个 ...

  10. Ansible系列(六):各种变量定义方式和变量引用

    本文目录:1.1 ansible facts1.2 变量引用json数据的方式 1.2.1 引用json字典数据的方式 1.2.2 引用json数组数据的方式 1.2.3 引用facts数据1.3 设 ...