vue实现结算淘宝购物车效果
- 实现单选时的价格,全选时价格
- 单选效果图

- 全选效果图

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()
}
}
vue实现结算淘宝购物车效果的更多相关文章
- vue实现淘宝购物车功能
淘宝购物车功能,效果如下图 非常简单的逻辑,没有做代码的封装,代码如下 <div class="list-container"> <div class=" ...
- 仿淘宝购物车demo---增加和减少商品数量
在上一篇博客中,小编简单的介绍了如何使用listview来实现购物车,但是仅仅是简单的实现了列表的功能,随之而来一个新的问题,买商品的时候,我们可能不止想买一件商品,想买多个,或许有因为某种原因点错了 ...
- jQuery实现淘宝购物车小组件
我爱撸码,撸码使我感到快乐! 大家好,我是Counter,本章将实现淘宝购物车小组件, 用原生js可以实现吗,当然可以,可是就是任性一回,就是想用jQuery 来实现下.HTML代码不多才4行,CSS ...
- Vue实现仿淘宝商品详情属性选择的功能
Vue实现仿淘宝商品详情属性选择的功能 先看下效果图:(同个属性内部单选,属性与属性之间可以多选) 主要实现过程: 所使用到的数据类型是(一个大数组里面嵌套了另一个数组)具体格式如下: attrA ...
- 淘宝购物车页面 智能搜索框Ajax异步加载数据
如果有朋友对本篇文章的一些知识点不了解的话,可以先阅读此篇文章.在这篇文章中,我大概介绍了一下构建淘宝购物车页面需要的基础知识. 这篇文章主要探讨的是智能搜索框Ajax异步加载数据.jQuery的社区 ...
- 淘宝购物车页面 PC端和移动端实战
最近花了半个月的时间,做了一个淘宝购物车页面的Demo.当然,为了能够更加深入的学习,不仅仅有PC端的固定宽度的布局,还实现了移动端在Media Query为768px以下(也就是实现了ipad,ip ...
- android ------ RecyclerView 模仿淘宝购物车
电商项目中常常有购物车这个功能,做个很多项目了,都有不同的界面,选了一个来讲一下. RecyclerView 模仿淘宝购物车功能(删除选择商品,商品计算,选择, 全选反选,商品数量加减等) 看看效果图 ...
- web——自己实现一个淘宝购物车页面
body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...
- Vue(小案例_vue+axios仿手机app)_购物车(二模拟淘宝购物车页面,点击加减做出相应变化)
一.前言 在上篇购物车中,如果用户刷新了当前的页面,底部导航中的数据又会恢复为原来的: 1.解决刷新,购物车上数值不变 ...
随机推荐
- 【刷题】BZOJ 5418 [Noi2018]屠龙勇士
www.lydsy.com/JudgeOnline/upload/noi2018day2.pdf Solution 将攻击的式子列出来,\(atk \times x-p \times y=a_i\) ...
- Springboot返回html
注:Springboot的版本2.1.3.RELEASE List-1 application.properties文件 server.port=8080 #url中,项目的前缀 server.ser ...
- 51nod 1636 教育改革 | DP
51nod 1636 教育改革 | DP 题面 最近A学校正在实施教育改革. 一个学年由n天组成.A学校有m门课程,每天学生必须学习一门课,一门课程必须在一天内学习完.在学习完第i门课程后,学生们会收 ...
- 【AGC010F】Tree Game
Description 有一棵\(n\)个节点的树(\(n \le 3000\)),第\(i\)条边连接\(a_i,b_i\),每个节点\(i\)上有\(A_i\)个石子,高桥君和青木君将在树上玩游戏 ...
- C++接口继承与实现继承的区别和选择
1.接口继承与实现继承的区别 <Effective C++>条款三十四:区分接口继承和实现继承中介绍的比较啰嗦,概括地说需要理解三点: (1)纯虚函数只提供接口继承,但可以被实现: (2) ...
- 洛谷P3994 Highway(树形DP+斜率优化+可持久化线段树/二分)
有点类似NOI2014购票 首先有方程$f(i)=min\{f(j)+(dep_i-dep_j)*p_i+q_i\}$ 这个显然是可以斜率优化的... $\frac {f(j)-f(k)}{dep_j ...
- 解题:POI 2011 Dynamite
题面 从零开始的DP学习系列之叁 树形DP的基本(常见?)思路:先递归进儿子,然后边回溯边决策,设状态时常设$dp[x]$表示以$x$为根的子树中(具体分析算不算$x$这个点)的情况 显然的二分答案, ...
- 解题:POI 2015 PUS
题面 还以为是差分约束,原来拓扑排序也能解决这样的问题=.= 类似差分约束的建图方式,我们把大小关系看做有向边.这样一来图上是不允许存在环的,于是我们可以做拓扑排序.然后问题来了,边数非常大,根本建不 ...
- uoj50【UR#3】链式反应
题解: 令$a(x)$为破坏死光的$EFG$,$f(x)$为方案的$EGF$:$f(x) = x + \int \ \frac{1}{2} f^2(x) a(x) \ dt$; 注意到$f(0)= ...
- 2018-2019 ACM-ICPC ECfinal I. Misunderstood … Missing
题目链接 首先有两个个属性值:\(A,D\),其中\(A\)表示目前攻击力,\(D\)表示每回合攻击的增量. 现在一共有\(n\)个回合,每一回合\(i\),可以有以下三种操作: 1.进行攻击,造成\ ...