elementUI -->实现简单的购物车
<template>
<div class="bbb">
<el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleAllChange">全选</el-checkbox>
<div style="margin: 15px 0;"></div>
<el-checkbox-group v-model="checkedGoods" @change="handleOneChange" class="aaa">
<el-checkbox v-for="good in goods" :label="good.name" :key="good.id">
<span style="width:150px;display:inline-block">商品名称: {{good.name}}</span>
<span style="width:150px;display:inline-block;margin-left:100px;margin-right:100px">商品价格: {{good.price}} 元</span>
<span> 商品数量:<el-input-number v-model="good.num" @change="handleChangeNum(good.id)" label="描述文字" size="small"></el-input-number></span>
<span style="width:150px;display:inline-block;margin-left:100px;margin-right:100px">小计: {{good.OnePrice}}元</span>
</el-checkbox>
</el-checkbox-group>
<div style="margin-top:40px;margin-left:450px;text-align:left">
<span style="margin-right:20px;display:inline-block">总价:{{allPrice}}元</span>
<el-button type="primary" size="small" @click="submitBtn">去结算<i class="el-icon-upload el-icon--right"></i></el-button>
</div> </div>
</template>
<script>
const goodOptions = ["哇哈哈", "辣条", "矿泉水", "西瓜", "苹果"];
export default {
data() {
return {
goods: [
{
id: ,
name: "哇哈哈",
price:
},
{
id: ,
name: "辣条",
price:
},
{
id: ,
name: "矿泉水",
price:
},
{
id: ,
name: "西瓜",
price:
},
{
id: ,
name: "苹果",
price:
}
],
checkAll: false,
isIndeterminate: true,
checkedGoods: [],
allPrice:
};
},
methods: {
handleAllChange(val) {
console.log(val, "");
this.checkedGoods = val ? goodOptions : [];
this.isIndeterminate = false;
if (val) {
this.getAllPrice();
} else {
this.allPrice = ;
}
},
handleOneChange(value) {
let a = ;
let checkedCount = value.length;
this.checkAll = checkedCount === this.checkedGoods.length;
this.isIndeterminate = checkedCount > && checkedCount < this.checkedGoods.length;
value.filter((it, id) => {
if (it == this.goods[id].name) {
if (this.goods[id].OnePrice) {
a += this.goods[id].OnePrice;
}
}
});
this.allPrice = a;
},
handleChangeNum(val) {
this.goods.filter((it, id) => {
if (it.id == val) {
it.OnePrice = it.num * it.price;
}
});
this.getAllPrice();
},
getAllPrice() {
//获取总价方法封装
let money = ;
this.goods.filter((it, id) => {
if (it.OnePrice) {
money += it.OnePrice;
}
});
this.allPrice = money;
},
submitBtn() {
this.$alert( this.allPrice+"元", "所有商品总计",{
confirmButtonText: "确定",
callback: action => {
this.$message({
type: "info",
message: "哈哈哈"
});
}
});
}
}
};
</script>
<style lang="postcss" scoped>
.bbb {
margin-left: 40px;
margin-top: 80px;
}
.aaa > label {
display: block;
text-align: left;
margin-top: 20px;
}
.el-checkbox {
display: block;
text-align: left;
}
</style>
elementUI -->实现简单的购物车的更多相关文章
- 使用MongoDB和JSP实现一个简单的购物车系统
目录 1 问题描述 2 解决方案 2.1 实现功能 2.2 最终运行效果图 2.3 系统功能框架示意图 2.4 有关MongoDB简介及系统环境配置 2.5 核心功能代码讲解 ...
- FineUI小技巧(1)简单的购物车页面
起因 最初是一位 FineUI 网友对购物车功能的需求,需要根据产品单价和数量来计算所有选中商品的总价. 这个逻辑最好在前台使用JavaScript实现,如果把这个逻辑移动到后台C#实现,则会导致过多 ...
- HTML5自学笔记[ 10 ]简单的购物车拖拽
用html5拖拽功能实现了一个简单的购物车,样式简陋,得学学画画提高下审美了T^T: <!doctype html> <html> <head> <meta ...
- 利用JSP编程技术实现一个简单的购物车程序
实验二 JSP编程 一.实验目的1. 掌握JSP指令的使用方法:2. 掌握JSP动作的使用方法:3. 掌握JSP内置对象的使用方法:4. 掌握JavaBean的编程技术及使用方法:5. 掌握JSP ...
- Python3学习之路~2.2 简单的购物车程序
程序:购物车程序 需求:启动程序后,让用户输入工资,然后打印商品列表允许用户根据商品编号购买商品用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 可随时退出,退出时,打印已购买商品和余额 代码 ...
- jQuery使用cookie与json简单实现购物车功能
本文实例讲述了jQuery使用cookie与json简单实现购物车的方法.分享给大家供大家参考,具体如下: 1.生成一个cookie 用来存储商品的id String类型 2.添加商品id的时候 把 ...
- react做的简单的购物车
###第一步 :首先电脑上已经安装react的脚手架 cnpm install create-react-app -g ###第二步 :创建项目 creact-react-app 项目 ...
- Java中的策略模式,完成一个简单地购物车,两种付款策略实例教程
策略模式是一种行为模式.用于某一个具体的项目有多个可供选择的算法策略,客户端在其运行时根据不同需求决定使用某一具体算法策略. 策略模式也被称作政策模式.实现过程为,首先定义不同的算法策略,然后客户端把 ...
- MVVM架构~knockoutjs实现简单的购物车
返回目录 概念相关 购物车相信大家都用过,很方便,可以将多个商品添加到购物车,并且可以修改购买商品的数据,当然为了用户体验好,在修改数据时,你的价格也会出现变化的,这使用JS可以实现,但我认为,代码量 ...
随机推荐
- Bash快捷操作
编辑命令 Ctrl + a :移到命令行首 Ctrl + e :移到命令行尾 Ctrl + f :按字符前移(右向) Ctrl + b :按字符后移(左向) Alt + f :按单词前移(右向) Al ...
- mysqli在php7中的使用
mysqli这个库还是比较繁杂的,这其中又分mysqli ,mysqli_stmt,mysqli_result......一堆类,特别乱 这里奉上thinkphp5.1中使用mysqli扩展的查询用法 ...
- 一个tornado框架下的文件上传案例
html部分----使用了form表单,注意三要素 method="post" action="/loaddata" enctype="multip ...
- web前端_js
在HTML中可以将JavaScript/JS的代码写在head中,被script标签所包裹,当浏览器解释HTML时,遇到style标签时,按照CSS规则解释,遇到Script标签时,按照JavaScr ...
- cdh搭建仓库
搭建内部仓库使用yum安装cm Creating a Permanent Internal Repository 1,安装httpd yum install httpd 删除/etc/httpd/co ...
- dockerfile:python-cuda-nvidia-cudnn
centos7 FROM centos:7 MAINTAINER yon@DataExa.com RUN yum -y install make wget \ && wget -O / ...
- 删除文件中的 ^M 字符
删除文件中的 ^M 字符 有时候,我们在 Linux 中打开曾在 Win 中编辑过的文件时,会在行尾看到 ^M 字符.虽然,这并不影响什么,但心里面还是有点不痛快.如果想要删除这些 ^M 字符,可以使 ...
- hdu 1208 Ignatius and the Princess III 划分数,dp
题目 题意:给你一个数字n,求将其划分成若干个数字相加总共有多少种划分数: <span style="font-size:24px;">#include <ios ...
- [转载]深入理解iostat
深入理解iostat 前言 iostat算是比较重要的查看块设备运行状态的工具,相信大多数使用Linux的同学都用过这个工具,或者听说过这个工具.但是对于这个工具,引起的误解也是最多的,大多数人对这个 ...
- White Lines
D. White Lines 主要思路就是利用差分 对于行:如果在某一个点上,向右下角涂掉 k*k 的矩形能够使得新出现一行 "B" 那么就在这个点上 +1(这里的加 +1 需要利 ...