zoukankan      html  css  js  c++  java
  • Vue 简单实例 购物车5

    1、结算按钮

    当选中商品时,按钮颜色有灰变红,并显示选中的商品总数量:

    <div class="btn-wrap">
          <a :class="['btn', 'btn--red', checkedCount != 0 ? '' : 'btn--dis']">结算({{ checkedCount }})</a>
    </div>
    
    <script>
    export default {
      methods: {
        // 选中的商品数量
        checkedCount() {
          let count = 0
          this.cartList.forEach(item => {
            if (item.checked) {
              count += item.productNum
            }
          })
          return count
        },
      }
    }
    </script>

    2、点击结算跳转到地址页

    给结算按钮添加点击事件:

    <a :class="['btn', 'btn--red', checkedCount != 0 ? '' : 'btn--dis']" @click="checkOut">结算({{ checkedCount }})</a>
    
    <script>
    export default {
      methods: {
        // 结算跳转
        checkOut() {
          if (this.checkedCount == 0) return
          this.$router.push('/address')
        }
      }
    }
    </script>

    当选中商品时,点击结算跳转到地址页。反之,点击结算按钮不跳转。

  • 相关阅读:
    2020软件工程02
    自我介绍
    2019年春总结作业
    第十二周作业
    第十一周作业
    第十周作业
    第九周作业
    第八周作业
    第七周学习总结
    第六周学习总结
  • 原文地址:https://www.cnblogs.com/joe235/p/12704810.html
Copyright © 2011-2022 走看看