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可以实现,但我认为,代码量 ...
随机推荐
- 面试题:Dubbo中zookeeper做注册中心,如果注册中心集群全都挂掉,发布者和订阅者之间还能通信么?
1.[提供者]在[启动]时,向注册中心zk [注册]自己提供的服务. 2.[消费者]在[启动]时,向注册中心zk [订阅]自己所需的服务. 可以的,消费者在启动时,消费者会从zk拉取注册的生产者的 ...
- hiho #1066 : 无间道之并查集
#1066 : 无间道之并查集 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 这天天气晴朗.阳光明媚.鸟语花香,空气中弥漫着春天的气息……额,说远了,总之,小Hi和小H ...
- 如何下载Direct3D9Ex
其实就是DirectX june_10月版本,下载链接如下 DirectX Software Development Kit 错误:安装报错“S1023" 若要解决此问题,必须在安装2010 ...
- CSS3 文字渐变动画
背景剪裁 语法:background-clip: border-box || padding-box || context-box || no-clip || text 本次用到的就是: -webki ...
- linux查看端口占用情况,python探测端口使用的小程序
Linux如何查看端口 1.lsof -i:端口号 用于查看某一端口的占用情况,比如查看8000端口使用情况,lsof -i:8000 # lsof -i:8000 COMMAND PID USER ...
- 「CEOI2008」order
题目链接 戳我 \(Solution\) 首先看看没有租条件的怎么弄.这很显然,就是普通最小割的套路 \(s\)向每个工作连一条流量\(x\)的边,\(x\)为工作收益 每个工作向每个机器连流量为\( ...
- C++入门经典-例5.1-输出变量的指针
1:代码如下: // 5.1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> using ...
- Miniui 表单验证
自定义表单验证: input输入框的表单验证可通过vtype和onvalidation事件两种方式实现 可编辑列表(例如div)的表单验证只能通过vtye来实现表单验证 (1)vtype方式: jsp ...
- 第六周课程总结&实验报告(四)
实验报告(四) 一.实验目的 1.掌握类的继承 2.变量的继承和覆盖,方法的继承,重载和覆盖的实现 二.实验的内容 1.根据下面的要求实现圆类Circle. 圆类Circle的成员变量:radius表 ...
- c++匿名函数精简写法
main.cpp: #include<stdio.h> #include<functional> #include<unistd.h> std::function& ...