<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="boots/bootstrap-3.3.7-dist/css/bootstrap.min.css">
<script src="boots/bootstrap-3.3.7-dist/jquery-1.11.3.min.js" type="text/javascript " charset="utf-8" ></script>
<script src="boots/bootstrap-3.3.7-dist/js/bootstrap.js" type="text/javascript " charset="utf-8" ></script>
<style>
table{
text-align: center;
}
</style>
</head>
<body>
<div id="app">
<table border="" cellspacing="0" width="800px">
<tr>
<td>编号</td>
<td>名称</td>
<td>单价</td>
<td>数量</td>
<td>总价</td>
</tr>
<tr v-for="(l,index) in msg">
<td >{{l.num}}</td>
<td>{{l.name}}</td>
<td>{{l.price}}</td>
<td>
<button v-on:click="jian(index)">-</button>
{{l.you}}
<button v-on:click="alk(index)">+</button></td>
<td>{{l.price*l.you}}</td>
</tr>
</tr>
<td>{{zong}]</td>
</tr>
</table>
</div>
<script src="js/vue.js"></script>
<script>
new Vue({
el:"#app",
data:{
msg:[
{
num:"1",
name:"袜子",
price:"5",
you:"1"
},
{
num:"2",
name:"外套",
price:"180",
you:"1"
},
{
num:"3",
name:"小黑子",
price:"2",
you:"1"
},
zong="0"
]
},
methods:{
//增加
alk:function(index){
this.msg[index].you++;
var total = 0;//临时总价
this.msg.forEach(function (l,index) {
total += l.price*l.you;
});
this.zong=parseFloat(total);
},
//减少
jian:function(index){
this.msg[index].you--;
}
}
})
</script>
</body>
</html>
vue.js 购物车
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...