• 实现单选时的价格,全选时价格
  • 单选效果图

  • 全选效果图

html

<template>
<!-- 淘宝结算购物车 -->
<div class="settlement-bill"> <div class="settlement-group"><div class="settlement-item" v-for="(item,index) in items" :key="item.id"><i  class="iconfont" @click="radioCheck(item,index)":class=" item.isChecked ? 'icon-yuanyixuan' : 'icon-yuanweixuan'" ></i><img :src="item.imgUrl" alt=""><div class="item-right"><p>{{item.content}}</p><span class="item-money">${{item.money}}</span><div class="item-num"><span @click="reduce(index)">-</span><span>{{item.num}}</span><span @click="add(index)">+</span></div></div></div></div><div class="settlement-bottom"><div class="bottom-left"><i @click="allCheck" class="iconfont " :class="checked ? 'icon-yuanyixuan' : 'icon-yuanweixuan' "></i><p>全选</p></div><div class="bottom-right"><p>合计<span class="total-money">{{total}}</span></p><div class="bottom-total">结算({{num}})</div></div><div class="clear"></div></div>
</div>
</template>

js

<script>
export default {data(){return {checked: false,items: [{id: 0,imgUrl: '../../static/timg.jpg',content: '云南白药牙膏家用去黄去口臭美白口气清新585g牙膏牙刷套装',money: 99,num: 1,},{id: 1,imgUrl: '../../static/maiguo.jpg',content: '湖南小台芒果带箱10斤小台芒果新鲜水果包邮',money: 39.9,num: 1},{id: 2,imgUrl: '../../static/baixiangguo.jpg',content: '广西新鲜热带水果百香果西番莲鸡蛋果10斤中果酸爽香甜',money: 69.8,num: 1}]}},computed: {total(){let sum = 0;this.items.forEach(item=>{if(item.isChecked == true)sum += (item.money*item.num)})return Math.round(sum*100)/100;},num() {let num = 0;this.items.forEach(item=>{if(item.isChecked == true)num += item.num})return num;}},methods: {// 减少宝贝reduce(index) {if(this.items[index].num === 1) return this.items[index].num--},// 增加宝贝add(index) {this.items[index].num++;},radioCheck(item,index) {let tmpState = !item.isChecked//改变单个状态this.$set(item,'isChecked',tmpState)//检测选择状态if(tmpState){let n = 0;this.items.forEach(itemu => {if(itemu.isChecked) n++;})if(n == this.items.length)this.checked = true;}else {this.checked = false;}},allCheck(){this.checked = !this.checked;for(let i = 0,len = this.items;i < len.length;i++){this.$set(this.items[i],'isChecked',this.checked)}}}}
</script>

css

<style lang="less">
* {padding: 0;margin: 0;
}
html,body,#app {height: 100%;
}
.settlement-bill {width: 100%;height: 100%;background:#e9eaeb;.settlement-group {padding: 20px;box-sizing: border-box;.settlement-item {position: relative;width: 100%;padding: 10px 5px;margin-bottom: 15px;box-sizing: border-box;background: #fff;.iconfont {position: absolute;top: 50%;left: 10px;margin-top: -10px;font-size: 20px;&.icon-yuanyixuan {color: orangered;}}img {display: inline-block;width: 100px;height: 100px;margin-left: 25px;}.item-right {display: inline-block;vertical-align: top;width: calc(100% - 130px);p {word-break: break-all;text-overflow: ellipsis;display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/-webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/-webkit-line-clamp: 2; /** 显示的行数 **/overflow: hidden;  /** 隐藏超出的内容 **/margin: 0 0 15px 0;}.item-money {display: inline-block;float: left;color: orangered;}.item-num {display: inline-block;float: right;span {display: inline-block;width: 25px;border: 1px solid #dcdfe6;text-align: center;&:nth-child(2){width: 50px;}}}}}}.settlement-bottom {position: fixed;bottom: 0;width: 100%;height: 60px;line-height: 60px;padding-left: 30px;padding-right: 25px;box-sizing: border-box;background: #fff;.bottom-left {float: left;display: inline-block;.iconfont {font-size: 20px;&.icon-yuanyixuan {color: orangered;}}p {display: inline-block;}}.bottom-right {display: inline-block;float: right;p {display: inline-block;.total-money {color: orangered;}}.bottom-total {display: inline-block;min-width: 80px;height: 50px;line-height: 50px;margin-top:5px;text-align: center;border-radius: 20px;background: orangered;color: #fff;}}.clear {clear: both;}}
}</style>
  • 想写这个小demo好久啦,终于写好。

遇到的vue3.0写法

 import { Watch, Component, Vue, Emit, Prop } from "vue-class-decorator";// 没有组件@component// 有组件// import children from "./components/children.vue";// @component({ components:{children} })export class MyChildren extends Vue{username = ""; // 名字//userId 父子之间传值,必传默认是null@Prop({ type: String, required: true, default: null})userId: string;@Emit("changeChildren")changeChildren(){}created(){}mounted(){}// 方法cancel() {// 调用自定义函数this.changeChildren()}}

转载于:https://www.cnblogs.com/DCL1314/p/10606992.html

vue实现结算淘宝购物车效果相关推荐

  1. vue实例--仿淘宝购物车

    下面是一张众所周知的淘宝购物车页面,今天要讲解的案例就是用vue.js做一个类似的页面 首先简单介绍一下可能会用到的一些vue.js的用法: v-bind,绑定属性:例如v-bind:class=&q ...

  2. 淘宝购物车效果(加,减,删除,全选)

    效果: 页面需要引入jquery,ArtTemplate 页面用假数据进行渲染 <!DOCTYPE html> <html lang="en"><he ...

  3. 2020用vue实现仿美团导航切换功能和淘宝购物车功能,实现默认第一个导航显示效果?

    总结:之前一直未写过同时实现跳转当前页面和跳转新页面的项目,要么是当前,要么是新页面,今天更新一个两个同时实现的项目. :相信很多人都遇到过router-link通过to跳转页面有时候会不显示内容的b ...

  4. python+selenium+chrome实现淘宝购物车秒杀自动结算

    python+selenium+chrome实现淘宝购物车秒杀自动结算 一.所需环境 二.安装 三.代码 最后run()一把就ok了!! 之前总是想要买aj,但是淘宝店铺每次发售手动抢的时候一般都会被 ...

  5. bootstrap淘宝购物车添加结算代码

    bootstrap淘宝购物车添加结算代码 jQuery制作淘宝商品购物车系统,支持全选.增加或减少.商品数量累计等功能.这是一款bootstrap布局的购物车结算页面设计代码. 演示地址 下载地址

  6. 高仿淘宝购物车分分钟让你集成

    前言 做商城类电商app购物车确实一直是一个难点,为什么难呢? 主要原因呢是他里面的逻辑复杂,然后 百度的资源好像都不太理想,好多就是一个简单的listView来实现根本就达不到开发的需求.然后 一般 ...

  7. HTML淘宝购物车页面的实现

    一.实验目的和要求 本实验任务用HTML基本标签制作一个简单的淘宝购物车页面,具体要求如下: 以纯文本格式保存为*.html文件 使用表格标签.div标签.span标签.图像标签等实现效果设计 启用浏 ...

  8. 淘宝购物车前端(JS和Angularjs版本)

    今天用HTML和JS实现以下购物车,然后再用Angualrjs再去实现一下购物车的前端实现. 功能页面分析: 既然是做模仿淘宝购物车,肯定要先去分析一下淘宝的购物车页面,自己去淘宝卖了两件东西,看了下 ...

  9. 测试网页版淘宝购物车

    测试网页版淘宝购物车 界面测试: 1. 购物车页面布局是否合理,显示是否完整 2. 鼠标浮动在购物车图标,迷你购物车界面显示是否正常 3. 不同店铺的商品在不同的区域正确显示 4. 页面的菜单功能栏正 ...

  10. Android一点 仿淘宝购物车动画

    首先看看ios上的淘宝购物车的动画效果ios淘宝购物车动画 我们实现的效果 看特效是分为两个界面,一个是主view,一个是弹出层.弹出层是用dialog实现的,只是加入了弹出的动画,这里就不分析了,我 ...

最新文章

  1. ubuntu服务器版编辑文件,Ubuntu 服务器版 18.04.4 固定 IP 设置
  2. Ubuntu查看硬件详细信息
  3. Microbiome:宏基因组分箱流程MetaWRAP简介
  4. linux设备驱动归纳总结(四):1.进程管理的相关概念【转】
  5. leetcode868
  6. VS2012生成ReactOS的VS工程失败(三)和 “ cl is not able to compile a simple test program“错误
  7. Qt phonon多媒体框架(转)
  8. python代码进去docker容器内_python脚本监控docker容器
  9. 定义带参数的C宏,方便输出调试信息
  10. Atitit WebDriver技术规范原理与概念
  11. python frame框架,第12讲,frame 框架控件
  12. AI人工智能的5种绝佳编程语言
  13. 2021年了!!Xshell7新手下载和安装教程(步骤超详细),以及远程与虚拟机连接
  14. 随机返回经典语句接口API
  15. 运维工程师面试题整理——》 IDC机房运维
  16. 仿西祠和搜狐论坛界面的bbs下载
  17. shui0418笔记
  18. WEB自动化_告警框处理(对话框、确认框、提示框、输入/编辑框、勾选框、单选框、复选框、下拉框)
  19. 远程直播服务器连接失败,哔哩哔哩直播姬连接失败如何解决 直播姬连接失败解决方法攻略大全...
  20. 分号与逗号的区别及举例_顿号和逗号的区别

热门文章

  1. Ajax的Promise应用
  2. 要读的书---培根说:历史使人明智,诗词使人巧慧,算学使人精密,哲理使人深刻,伦理学人庄重,逻辑修辞使人善辩。...
  3. 桌面计算机未响应怎么办,电脑卡死程序未响应的解决方法步骤详解
  4. ppt将画好的箭头改为直线
  5. 1.10全角色FCR,FBR,FHR表
  6. ashampoo(阿香婆) movie studio视频剪辑笔记
  7. [单片机框架][bsp层][AT32F415][bsp_tim] tim定时器配置和使用
  8. VMware Ubuntu安装详细过程(非常靠谱)
  9. 曲线拟合(多项式函数+MATLAB实例)
  10. ArcBlock 将作证支持美国华盛顿州区块链立法 | ABT 活动