日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue.js购物车

發布時間:2024/4/17 vue 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue.js购物车 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

vue.js

https://cn.vuejs.org/v2/guide/

簡單購物車

<html><head><script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script><style>table {border: 1px solid black;}table {width: 100%; border-spacing: 0;}th {background-color: #ddd;}th,td {border-bottom: 1px solid #ddd;height: 50px;text-align:center;}.red {color: red}.green {color: green}</style> </head><body><div id="app"><table><tr><th>序號</th><th>商品名稱</th><th>商品價格</th><th>購買數量</th><th>操作</th></tr><tr v-for="iphone in PJson"><td>{{ iphone.id }}</td><td>{{ iphone.name }}</td><td class="red">¥{{ iphone.price }}</td><td><button v-bind:disabled="iphone.count == 1" v-on:click="iphone.count-=1" v-bind:class="{green:iphone.count>1,red:iphone.count==1}">-</button>{{ iphone.count }}<button v-bind:disabled="iphone.count == 9" v-on:click="iphone.count+=1" v-bind:class="getBtnClass(iphone.count)">+</button></td><td><button v-on:click="del($index)">移除</button></td></tr></table><p>說明:滿100包郵,每個商品限購9件</p><p><span class="red">總價:¥{{totalPrice()}}</span><span class="green" v-if="totalPrice()>0" v-show="youfei>0">(含郵費¥{{youfei}})</span><span class="green" v-show="youfei==0">(包郵)</span></p></div><script>var app = new Vue({el: '#app',data: {youfei: 10,PJson: [{id: 1,name: 'iphone1',price: 10,count: 1},{id: 2,name: 'iphone2',price: 20,count: 1},{id: 3,name: 'iphone3',price: 30,count: 1}]},computed: {//寫在methods里也可以的 getBtnClass(){return function(num){return{green:num<9,red:num==9}}}},/*computed: {youhui:function(){return 100}},*/methods: {del: function (ii) {this.PJson.splice(ii, 1);},totalPrice: function () {var totalP = 0;for (var i = 0, len = this.PJson.length; i < len; i++) {totalP += this.PJson[i].price * this.PJson[i].count;}if (totalP >= 100) {this.youfei = 0} else {this.youfei = 10}if (totalP > 0) {return totalP + this.youfei;}return 0;},getBtnClass2:function(num){return{green:num<9,red:num==9}}}})</script> </body></html>

?

轉載于:https://www.cnblogs.com/webapi/p/10584587.html

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的vue.js购物车的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。