首页 > 其他 > 详细

Vue 简单实例 购物车5 - 结算

时间:2020-04-26 14:35:33      阅读:47      评论:0      收藏:0      [点我收藏+]

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>

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

技术分享图片

Vue 简单实例 购物车5 - 结算

原文:https://www.cnblogs.com/joe235/p/12704810.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!