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.gepszalag.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>名稱(chēng)</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. 怎樣才能用js生成xmldom對(duì)象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?2. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)車(chē)輛管理系統(tǒng)3. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算4. ASP.Net MVC利用NPOI導(dǎo)入導(dǎo)出Excel的示例代碼5. jstl 字符串處理函數(shù)6. JSP動(dòng)態(tài)網(wǎng)頁(yè)開(kāi)發(fā)原理詳解7. PHP中為什么使用file_get_contents("php://input")接收微信通知8. .Net core Blazor+自定義日志提供器實(shí)現(xiàn)實(shí)時(shí)日志查看器的原理解析9. IOS蘋(píng)果AppStore內(nèi)購(gòu)付款的服務(wù)器端php驗(yàn)證方法(使用thinkphp)10. XML CDATA是什么?
