Vue实现购物车,超简单

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue购物车(runoob.com)</title>
<script src="Vue.js"></script>
</head>
<style>
	#app{
		box-sizing: border-box;
		width:550px;
		height:550px;
		position: relative;
		margin: 150px auto;
		background: steelblue;
		border-radius: 3px;
		text-align: center;
		color: white;
		padding: 5px 50px;
	}
	h1{
		font-size: 55px;
		text-shadow: 0px 3px 0px rgba(0,0,0,0.1);
	}
	.sp{
		width:400px;
		height:75px;
		background: rgb(142,193,109);
		margin: 10px auto;
		font-weight: bolder;
		line-height: 75px;
		font-size: 24px;
		cursor: pointer;
	}
	.left{
		float: left;
		text-indent: 1.5em;
	}
	.right{
		float: right;
		position: relative;
		right:1.5em;
	}
	.truea{
		background: indianred;
	}
	hr{
		width:400px;
		margin:10px auto;
		border-color: white;
	}
</style>
<body>
<div id="app">
  <h1 class="head">Services</h1>
  <div class="sp" v-bind:class="site.active+'a'" v-on:click="site.active=!site.active;check()"  v-for="site in sites">
	  <span class="left">{{site.name}}</span>
	  <span class="right">${{site.price}}</span>
  </div>
  <hr size="1" />
  <p>${{total}}</p>
</div>
<script>
	new Vue({
		el:"#app",
		data:{
			sites:[
				{name:"Web Development",price:300,active:false},
				{name:"Design",price:400,active:false},
				{name:"Integration",price:250,active:false},
				{name:"Traning",price:200,active:false}
			],
			total:0
		},
		methods:{
			check:function(){
				this.total=0
				for(let i=0;i<this.sites.length;i++)
				{
					if(this.sites[i].active)
					{
						this.total+=this.sites[i].price
					}
				}
			}
		}
	})
</script>
</body>
</html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值