我是靠谱客的博主 多情高山,这篇文章主要介绍vue实现购物车的监听,现在分享给大家,希望可以做个参考。

利用vue简单实现购物车的监听,供大家参考,具体内容如下

主要运用的vue的监听,有兴趣的可以看看实现过程

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>利用vue实现对购物车的监听</title> <script src="../vue.js"></script> <style type="text/css"> table{ border: 1px solid black; width: 100%; text-align: center; } th{ height: 50px; } th, td{ border-bottom: 1px solid #ddd; border-right: 1px solid #ddd; } </style> </head> <body> <div id="app"> <h1>订单系统</h1> <table> <tr> <th>编号</th> <th>名称</th> <th>品牌</th> <th>价格</th> <th>数量</th> <th>操作</th> </tr> <tr v-for="val in items"> <td>{{val.id}}</td> <td>{{val.name}}</td> <td>{{val.pinpai}}</td> <td>{{val.price}}</td> <td> <!-- 如果count等于0执行v-bind 绑定一个点击事件 --> <button v-bind:disabled="val.count === 0" @click="val.count-=1">-</button> {{val.count}} <button @click="val.count+=1">+</button> </td> <td> <button v-on:click="val.count = 0">移除</button> </td> </tr> </table> <!-- 调用totalPrice --> 你所需要支付总额为:${{totalPrice()}} </div> <script type="text/javascript" charset="UTF-8"> var vm = new Vue({ el:"#app", data:{ items:[{ id:1, name:'上衣', pinpai:'阿迪达斯', price:100, count:1 }, { id:2, name:'裤子', pinpai:'安踏', price:528, count:1 }, { id:3, name:'鞋子', pinpai:'耐克', price:999, count:1 }] }, methods:{ totalPrice:function(){ var totalPri = 0; //总价等于数量乘以数量 for(var i=0;i<this.items.length;i++){ totalPri += this.items[i].price*this.items[i].count; } return totalPri; } } }); </script> </body> </html>

实现效果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。

最后

以上就是多情高山最近收集整理的关于vue实现购物车的监听的全部内容,更多相关vue实现购物车内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(141)

评论列表共有 0 条评论

立即
投稿
返回
顶部