vus购物车

1.引入vue.js

<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/vue.min.js" type="text/javascript" charset="utf-8"></script>

2.完整代码(不解释那么多,不懂自己领悟去)

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
		table{
	border:1px solid #e9e9e9;
	border-collapse: collapse;
    border-spacing: 0;
}

th,td{
	padding: 8px 16px;
	border: 1px solid #e9e9e9;
	text-align: left;
}

th{
	background-color: #f7f7f7;
	color:#5c6b77;
	font-weight: 600;
}
.image{
	width: 100px;
}

	</style>
	</head>
	<body>
		<div id="app">
			<div v-if="boolist.length>0">
				<table border="" cellspacing="" cellpadding="">
					<tr>
						<td></td>
						<!-- <td>全选<input type="checkbox" name="" id="" value="" /></td> -->
						<td>商品名</td>
						<td>图片</td>
						<td>时间</td>
						<td>价格</td>
						<td>购买数量</td>
						<td>删除</td>
					</tr>

					<tr v-for="(a,i) in boolist">
						<td>{{a.id}}</td>
						<td>{{a.name}}</td>
						<td><img v-bind:src="a.image" v-bind:class="{image:a.images}" width="50px" @mouseenter="enter(i)" @mouseleave="leave(i)" /></td>
						<td>{{a.data}}</td>
						<td>¥:{{a.price}}</td>
						<td><button type="button" @click="aa(i)">+</button>
							<input type="text" style="width: 10px;" v-model="a.count" />
							<button type="button" @click="ab(i)">-</button></td>
						<td><button type="button" @click="ac(i)">删除</button></td>
					</tr>
				</table>
				<p>
					总价格:{{aas}}
				</p>

			</div>
			<div v-else>
				没有商品了
			</div>
		</div>
	</body>
	<script type="text/javascript" >
		let a = new Vue({
			el: "#app",
			data: {
				boolist: [{
						id: 1,
						images: false,
						"image": "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2442805491,865665720&fm=26&gp=0.jpg",
						name: 'Vue.js实战',
						data: '2015-11-19',
						price: 35,
						count: 1
					},
					{
						id: 2,
						images: false,
						"image": "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2442805491,865665720&fm=26&gp=0.jpg",
						name: 'Vue.js实战',
						data: '2014-03-21',
						price: 45,
						count: 1
					},
					{
						id: 3,
						images: false,
						"image": "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2442805491,865665720&fm=26&gp=0.jpg",
						name: 'Vue.js实战',
						data: '2012-05-03',
						price: 85.23,
						count: 1
					},
					{
						id: 4,images: false,
						
						"image": "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2442805491,865665720&fm=26&gp=0.jpg",
						name: 'Vue.js实战',
						data: '2016-01-01',
						price: 73,
						count: 1
					},
					{
						id: 5,
						images: false,
						"image": "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2442805491,865665720&fm=26&gp=0.jpg",
						name: 'Vue.js实战',
						data: '2017-08-15',
						price: 15,
						count: 1
					}
				]
			},
			methods: {
				aa: function(i) {
					this.boolist[i].count++;
				},
				ab: function(i) {
					if (this.boolist[i].count <= 0) {
						alert("已经没有商品了哦");
					} else {
						this.boolist[i].count--;
					}
				},
				ac: function(s) {
					this.boolist.splice(s, 1);
				},
				enter: function(s) {
					this.boolist[s].images = true;
				},
				leave: function(s) {
					this.boolist[s].images = false;
				}
			},
			computed: {
				aas: function() {
					// return this.item[0].a;
					let ss = 0;
					for (let j = 0; j < this.boolist.length; j++) {
						ss += this.boolist[j].price * this.boolist[j].count;
					}
					return ss.toFixed(2);
				}
			}
		})
	</script>
</html>

3.实现图片
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值