vue實(shí)現(xiàn)購物車的監(jiān)聽
利用vue簡單實(shí)現(xiàn)購物車的監(jiān)聽,供大家參考,具體內(nèi)容如下
主要運(yùn)用的vue的監(jiān)聽,有興趣的可以看看實(shí)現(xiàn)過程
<!DOCTYPE html><html> <head> <meta charset='utf-8'> <title>利用vue實(shí)現(xiàn)對購物車的監(jiān)聽</title> <script src='http://m.lshqa.cn/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>編號</th> <th>名稱</th> <th>品牌</th> <th>價格</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 綁定一個點(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; //總價等于數(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)效果:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能2. 利用ajax+php實(shí)現(xiàn)商品價格計(jì)算3. 利用FastReport傳遞圖片參數(shù)在報(bào)表上展示簽名信息的實(shí)現(xiàn)方法4. chat.asp聊天程序的編寫方法5. 網(wǎng)頁中img圖片使用css實(shí)現(xiàn)等比例自動縮放不變形(代碼已測試)6. PHP循環(huán)與分支知識點(diǎn)梳理7. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫的方法8. JSP之表單提交get和post的區(qū)別詳解及實(shí)例9. Ajax請求超時與網(wǎng)絡(luò)異常處理圖文詳解10. jsp實(shí)現(xiàn)登錄驗(yàn)證的過濾器
