欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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,計算當(dāng)前勾選的商品總價
 _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ù)量計算每一個商品對應(yīng)的總金額
  }
  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é)賬頁面實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • 一文帶你了解threejs在vue項目中的基本使用

    一文帶你了解threejs在vue項目中的基本使用

    three.js是一個用于在Web上創(chuàng)建三維圖形的JavaScript庫,它可以用于創(chuàng)建各種類型的三維場景,包括游戲、虛擬現(xiàn)實、建筑和產(chǎn)品可視化等,下面這篇文章主要給大家介紹了關(guān)于如何通過一文帶你了解threejs在vue項目中的基本使用,需要的朋友可以參考下
    2023-04-04
  • vue中activated的用法

    vue中activated的用法

    這篇文章主要介紹了vue中activated的用法,幫助大家更好的理解和使用vue框架,感興趣的朋友可以了解下
    2021-01-01
  • vue.js踩坑之ref引用細節(jié)點講解

    vue.js踩坑之ref引用細節(jié)點講解

    這篇文章主要介紹了vue.js踩坑之ref引用細節(jié)點講解,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • vue單頁應(yīng)用中如何使用jquery的方法示例

    vue單頁應(yīng)用中如何使用jquery的方法示例

    最近在工作中遇到的一個需求,需要在vue-cli建立的應(yīng)用中引入jquery的方式,通過查找相關(guān)的資料最終解決了,所以這篇文章主要給大家介紹了關(guān)于在vue單頁應(yīng)用中如何使用jquery的方法示例,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-07-07
  • 使用寶塔面板中Nginx部署前端Vue項目完整步驟

    使用寶塔面板中Nginx部署前端Vue項目完整步驟

    在Kubernetes(K8S)部署前端Vue項目通常會涉及到使用Nginx作為靜態(tài)資源服務(wù)器的一個重要部分,這篇文章主要給大家介紹了關(guān)于使用寶塔面板中Nginx部署前端Vue項目的相關(guān)資料,需要的朋友可以參考下
    2024-10-10
  • VUE中的export default和export使用方法解析

    VUE中的export default和export使用方法解析

    export default和export都能導(dǎo)出一個模塊里面的常量,函數(shù),文件,模塊等,在其它文件或模塊中通過import來導(dǎo)入常量,函數(shù),文件或模塊。但是,在一個文件或模塊中export,import可以有多個,export default卻只能有一個。
    2022-12-12
  • 使用vue-antd動態(tài)切換主題

    使用vue-antd動態(tài)切換主題

    這篇文章主要介紹了使用vue-antd動態(tài)切換主題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • Vue多環(huán)境代理配置方法思路詳解

    Vue多環(huán)境代理配置方法思路詳解

    多人協(xié)作模式下,修改代理比較麻煩,而且很容易某個開發(fā)人員會修改了vue.config.js文件后提交了。接下來通過本文給大家分享Vue多環(huán)境代理配置方法思路詳解,需要的朋友可以參考下
    2019-06-06
  • SpringBoot+Vue 前后端合并部署的配置方法

    SpringBoot+Vue 前后端合并部署的配置方法

    這篇文章主要介紹了SpringBoot+Vue 前后端合并部署的配置方法,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12
  • 解決element-ui的el-select選擇器的@blur事件失效的坑

    解決element-ui的el-select選擇器的@blur事件失效的坑

    這篇文章主要介紹了解決element-ui的el-select選擇器的@blur事件失效的坑,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09

最新評論