vue實(shí)現(xiàn)購(gòu)物車(chē)的監(jiān)聽(tīng)
利用vue簡(jiǎn)單實(shí)現(xiàn)購(gòu)物車(chē)的監(jiān)聽(tīng),供大家參考,具體內(nèi)容如下
主要運(yùn)用的vue的監(jiān)聽(tīng),有興趣的可以看看實(shí)現(xiàn)過(guò)程
<!DOCTYPE html><html> <head> <meta charset='utf-8'> <title>利用vue實(shí)現(xiàn)對(duì)購(gòu)物車(chē)的監(jiān)聽(tīng)</title> <script src='http://www.piao2010.com/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>訂單系統(tǒng)</h1> <table> <tr> <th>編號(hào)</th> <th>名稱</th> <th>品牌</th> <th>價(jià)格</th> <th>數(shù)量</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執(zhí)行v-bind 綁定一個(gè)點(diǎn)擊事件 --> <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> <!-- 調(diào)用totalPrice --> 你所需要支付總額為:${{totalPrice()}} </div> <script type='text/javascript' charset='UTF-8'> var vm = new Vue({ el:'#app', data:{ items:[{ id:1, name:’上衣’, pinpai:’阿迪達(dá)斯’, 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; //總價(jià)等于數(shù)量乘以數(shù)量 for(var i=0;i<this.items.length;i++){ totalPri += this.items[i].price*this.items[i].count; } return totalPri; } } }); </script> </body></html>
實(shí)現(xiàn)效果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP中實(shí)現(xiàn)字符部位類似.NET里String對(duì)象的PadLeft和PadRight函數(shù)2. vue前端RSA加密java后端解密的方法實(shí)現(xiàn)3. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能4. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)財(cái)務(wù)記賬管理系統(tǒng)5. vue項(xiàng)目登錄成功拿到令牌跳轉(zhuǎn)失敗401無(wú)登錄信息的解決6. 淺談?dòng)蓀osition屬性引申的css進(jìn)階討論7. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享8. php使用正則驗(yàn)證密碼字段的復(fù)雜強(qiáng)度原理詳細(xì)講解 原創(chuàng)9. 基于jsp+mysql實(shí)現(xiàn)在線水果銷售商城系統(tǒng)10. CSS可以做的幾個(gè)令你嘆為觀止的實(shí)例分享

網(wǎng)公網(wǎng)安備