最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實現(xiàn)仿淘寶結(jié)賬頁面實例代碼

 更新時間:2017年11月08日 08:34:01   作者:愛喝酸奶的吃貨  
本文是小編給大家分享的vue實現(xiàn)仿淘寶結(jié)賬頁面實例代碼,主要功能是仿照淘寶頁面的結(jié)算購物車商品時自動算出合計價格的頁面,具體實例代碼大家參考下本文

雖然Vue最強大的是組件化開發(fā),但是其實多頁面開發(fā)也蠻適合的。下面小編給大家分享vue實現(xiàn)仿淘寶結(jié)賬頁面實例代碼,具體內(nèi)容大家參考下本文。

這個demo,是小編基于之前的 vue2.0在table中實現(xiàn)全選和反選  文章進行更新后的demo,主要功能呢,是仿照淘寶頁面的結(jié)算購物車商品時自動算出合計價格的頁面,具體頁面效果請看下面的動圖:(如果大家發(fā)現(xiàn)有什么問題請及時提出幫小穎改正錯誤呦,謝謝啦嘻嘻)

效果圖:

更新后的home.vue

<template>
 <div class="container">
 <div class="checkout-title">
  <span>購物車</span>
 </div>
 <table class="product_table">
  <tbody>
  <template v-for="(list,index) in table_list">
   <tr>
   <td width="7%" min-width="94px" v-if="index===0">
    <input type="checkbox" v-model='checked' @click='checkedAll'>
   </td>
   <td width="7%" v-if="index!==0">
    <input type="checkbox" v-model='checkList' :value="list.id" @click=checkProductFun(index,$event)>
   </td>
   <td width="43%">{{list.product_inf}}</td>
   <td width="10%" v-if="index===0">{{list.product_price}}</td>
   <td width="10%" v-if="index!==0">&yen;{{list.product_price}}</td>
   <td width="10%" v-if="index===0">{{list.product_quantity}}</td>
   <td width="10%" v-if="index!==0">
    <a class="numbers plus" href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" @click="changeMoney(index,-1)">-</a>
    <input class="txt_number" type="text" v-model="list.product_quantity" size="1" disabled>
    <a class="numbers reduce" href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" @click="changeMoney(index,1)">+</a>
   </td>
   <td width="10%">{{list.total_amount}}</td>
   <td width="20%" v-if="index===0">編輯</td>
   <td width="20%" v-if="index!==0">
    <a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="update">修改</a>
    <a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="delete">刪除</a>
   </td>
   </tr>
  </template>
  </tbody>
 </table>
 <div class="price_total_bottom">
  <div class="price_total_ms">
  <label>合計:{{allProductTotal}}</label>
  <router-link to="/userAddress">結(jié)賬</router-link>
  </div>
 </div>
 </div>
</template>
<script>
import userAddress from './address'
export default {
 components: {
 userAddress
 },
 data() {
 return {
  table_list: [{
  'id': 0,
  'product_inf': '商品信息',
  'product_price': '商品金額',
  'product_quantity': '商品數(shù)量',
  'total_amount': '總金額'
  }, {
  'id': '1',
  'product_inf': '女士銀手鏈',
  'product_price': 100,
  'product_quantity': 10,
  'total_amount': 1000
  }, {
  'id': '2',
  'product_inf': '女士銀手鐲',
  'product_price': 200,
  'product_quantity': 5,
  'total_amount': 1000
  }, {
  'id': '3',
  'product_inf': '女士銀耳環(huán)',
  'product_price': 50,
  'product_quantity': 10,
  'total_amount': 500
  }],
  checked: false,
  allProductTotal: null,
  checkList: ['1', '3']
 }
 },
 mounted: function() {
 var _this = this;
 // 根據(jù)data中默認勾選的checkbox,計算當前勾選的商品總價
 _this.allProductTotal = 0;
 this.checkList.forEach(function(element1, index1) {
  _this.table_list.forEach(function(element2, index2) {
  if (element1 == element2.id) {
   _this.$set(_this.table_list[index2], 'checked', true);
   _this.allProductTotal += element2.product_price * element2.product_quantity;
  }
  });
 });
 },
 methods: {
 checkedAll: function() {
  var _this = this;
  _this.allProductTotal = 0;
  if (_this.checked) { //實現(xiàn)反選
  _this.checkList = [];
  _this.table_list.forEach(function(item, index) {
   if (_this.table_list[index].checked) {
   _this.table_list[index].checked = false;
   }
  });
  } else { //實現(xiàn)全選
  _this.checkList = [];
  _this.table_list.forEach(function(item, index) {
   if (index > 0) {
   _this.checkList.push(item.id);
   if (!_this.table_list[index].checked) {
    _this.$set(_this.table_list[index], 'checked', true);
   } else {
    _this.table_list[index].checked = true;
   }
   if (item.checked) {
    _this.allProductTotal += item.product_price * item.product_quantity;
   }
   }
  });
  }
 },
 checkProductFun(index, event) { //根據(jù)checkbox是否勾選,計算勾選后的商品總價
  var _this = this;
  _this.allProductTotal = 0;
  if (event.target.checked) {
  if (!_this.table_list[index].checked) {
   _this.$set(_this.table_list[index], 'checked', true);
  }
  } else {
  if (_this.table_list[index].checked) {
   _this.table_list[index].checked = false;
  }
  }
  this.table_list.forEach(function(item, index) {
  if (item.checked) {
   _this.allProductTotal += item.product_price * item.product_quantity;
  }
  });
 },
 changeMoney: function(index, way) {
  if (way > 0) {
  this.table_list[index].product_quantity++;
  } else {
  this.table_list[index].product_quantity--;
  if (this.table_list[index].product_quantity < 1) {
   this.table_list[index].product_quantity = 1;
  }
  }
  this.calcTotalPrice();
 },
 calcTotalPrice: function() {
  var _this = this;
  _this.allProductTotal = 0;
  this.table_list.forEach(function(item, index) {
  if (index > 0) { //因為第一行為表頭不需要進行計算
   item.total_amount = item.product_price * item.product_quantity; //根據(jù)商品數(shù)量計算每一個商品對應的總金額
  }
  if (item.checked) {
   _this.allProductTotal += item.product_price * item.product_quantity; //根據(jù)是否否選該商品的checkbox,計算總價
  }
  });
 },
 },
 watch: { //深度 watcher
 'checkList': {
  handler: function(val, oldVal) {
  if (val.length === this.table_list.length - 1) {
   this.checked = true;
  } else {
   this.checked = false;
  }
  },
  deep: true
 }
 }
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.container {
 padding: 69px 0 54px 0;
}
table {
 border-collapse: collapse;
 border-color: transparent;
 text-align: center;
}
.product_table,
.product_table tbody {
 width: 100%
}
.product_table tr:first-child {
 background: #ece6e6;
 color: #e66280;
 font-size: 20px;
}
.product_table td {
 border: 1px solid #f3e8e8;
 height: 62px;
 line-height: 62px;
}
.product_table a.update:link,
.product_table a.update:visited,
.product_table a.update:hover,
.product_table a.update:active {
 color: #1CE24A;
}
.product_table a.delete:link,
.product_table a.delete:visited,
.product_table a.delete:hover,
.product_table a.delete:active {
 color: #ffa700;
}
.product_table .txt_number {
 text-align: center;
}
.product_table .numbers {
 font-weight: bold;
}
.price_total_bottom {
 font-size: 20px;
 padding: 20px 10px;
}
.price_total_ms {
 text-align: right;
}
.price_total_bottom .price_total_ms label {
 margin-right: 100px;
}
.price_total_bottom .price_total_ms a {
 cursor: default;
 text-align: center;
 display: inline-block;
 font-size: 20px;
 color: #fff;
 font-weight: bold;
 width: 220px;
 height: 54px;
 line-height: 54px;
 border: 0;
 background-color: #f71455;
}
</style>

總結(jié)

以上所述是小編給大家介紹的vue實現(xiàn)仿淘寶結(jié)賬頁面實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關文章

  • vue實現(xiàn)帶縮略圖的輪播圖效果

    vue實現(xiàn)帶縮略圖的輪播圖效果

    這篇文章主要為大家詳細介紹了如何使用vue實現(xiàn)帶縮略圖的輪播圖效果,文中的示例代碼講解詳細,具有一定的借鑒價值,有需要的可以參考下
    2024-02-02
  • 創(chuàng)建nuxt.js項目流程圖解

    創(chuàng)建nuxt.js項目流程圖解

    Nuxt.js是創(chuàng)建Universal Vue.js應用程序的框架。它的主要范圍是UI渲染,同時抽象出客戶端/服務器分布。我們的目標是創(chuàng)建一個足夠靈活的框架,以便您可以將其用作主項目庫或基于Node.js的當前項目。
    2020-03-03
  • vue實現(xiàn)抖音時間轉(zhuǎn)盤

    vue實現(xiàn)抖音時間轉(zhuǎn)盤

    這篇文章主要為大家詳細介紹了vue實現(xiàn)抖音時間轉(zhuǎn)盤,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • Vue3實現(xiàn)pdf在線預覽的三種方式

    Vue3實現(xiàn)pdf在線預覽的三種方式

    這篇文章主要為大家詳細介紹了使用Vue3實現(xiàn)pdf在線預覽的三種常用方式,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下
    2025-02-02
  • Vue Element前端應用開發(fā)之圖標的維護和使用

    Vue Element前端應用開發(fā)之圖標的維護和使用

    在Vue Element前端應用中,圖標是必不可少點綴界面的元素,Element界面組件里面提供了很多常見的圖標,因此考慮擴展更多圖標,引入了vue-awesome組件,它利用了Font Awesome的內(nèi)置圖標,實現(xiàn)了更多圖標的整合,可以在項目中使用更多的圖標元素了
    2021-05-05
  • Vue學習筆記之計算屬性與偵聽器用法

    Vue學習筆記之計算屬性與偵聽器用法

    這篇文章主要介紹了Vue學習筆記之計算屬性與偵聽器用法,結(jié)合實例形式詳細分析了vue.js計算屬性與偵聽器基本功能、原理、使用方法及操作注意事項,需要的朋友可以參考下
    2019-12-12
  • Vue 實現(xiàn)一個命令式彈窗組件功能

    Vue 實現(xiàn)一個命令式彈窗組件功能

    這篇文章主要介紹了vue實現(xiàn)命令式彈窗組件功能,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-09-09
  • 基于Vue2實現(xiàn)移動端圖片上傳、壓縮、拖拽排序、拖拽刪除功能

    基于Vue2實現(xiàn)移動端圖片上傳、壓縮、拖拽排序、拖拽刪除功能

    這篇文章主要介紹了基于Vue2實現(xiàn)移動端圖片上傳、壓縮、拖拽排序、拖拽刪除功能,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-01-01
  • Vue中的路由跳轉(zhuǎn)及傳參的多種方法小結(jié)

    Vue中的路由跳轉(zhuǎn)及傳參的多種方法小結(jié)

    這篇文章主要介紹了Vue中的路由跳轉(zhuǎn)及傳參的多種方法小結(jié),本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2023-11-11
  • vue實現(xiàn)輸入框只允許輸入數(shù)字

    vue實現(xiàn)輸入框只允許輸入數(shù)字

    在vue項目中,輸入框只允許輸入數(shù)字,現(xiàn)將自己使用的一種方法記錄,本文結(jié)合實例代碼給大家介紹的非常詳細,感興趣的朋友一起看看吧
    2023-11-11

最新評論

徐汇区| 诸城市| 河东区| 安多县| 集贤县| 江源县| 蒙自县| 葵青区| 池州市| 工布江达县| 三门县| 五原县| 常德市| 安陆市| 定襄县| 喀喇沁旗| 饶阳县| 洛隆县| 五寨县| 昆山市| 新化县| 宜君县| 疏勒县| 收藏| 贵溪市| 藁城市| 腾冲县| 华亭县| 江川县| 宁阳县| 义乌市| 罗城| 库伦旗| 图木舒克市| 泾源县| 紫金县| 旬邑县| 克什克腾旗| 盱眙县| 肇源县| 娄底市|