码迷,mamicode.com
首页 > 其他好文 > 详细

Vue仿淘宝订单状态的tab切换效果——全

时间:2020-05-15 09:44:05      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:评价   ali   ace   def   border   ack   nextTick   std   fine   

以下代码直接复制到vue文件中即可用
一、template代码
<template>
  <div class="orderIndex">
    <div class="orderTop">
      <div class="orderSearch">
        <div class="searchBox">
          <form>
            <i class="iconfont icon-search"></i>
            <input type="text" placeholder="搜索订单信息" />
          </form>
        </div>
        <span>搜索</span>
      </div>
      <ul class="tab" :style="{height: tabheight}">
        <li
          ref="iWidth"
          v-for="(item,index) in tabList"
          :key="index"
          :class="{‘on‘: checkindex == index}"
          @click="checkli(index)"
        >{{item}}</li>
        <i :style="{transform:`translateX(${iWidths/2+checkindex*iWidths}px) translateX(-50%)`}"></i>
      </ul>
    </div>
    <div class="orderContent">
      <ul>
        <li class="item paddingDiv" v-for="(item,index) in orderAllItem[checkindex]" :key="index">
          {{item.orderType}}  
        </li>
      </ul>
      <p class="overBottom">已经到底了</p>
    </div>
  </div>
</template>

二、js

<script>
export default {
  name: "orderIndex",
  data() {
    return {
      tabheight: "1rem",
      checkindex: 0, //点击的是导航中的哪一个
      tabList: ["全部订单", "待付款", "待收货", "待评价"],
      iWidths: 0, //获取tab导航li的宽度
      orderAllItem: [], //全部订单分类的集合
      pendingPayment: [], //待付款订单集合
      toBeReceived: [], //待收货订单集合
      beEvaluated: [] //待评价订单集合
    };
  },

  mounted() {
    //实现tab下划线跟随导航样式切换
    var tab = this.$route.query.tab;
    if (tab != undefined && tab != "undefined" && tab != null && tab != "") {
      this.checkindex = tab;
    }
    this.$nextTick(function() {
      this.iWidths = this.$refs.iWidth[0].clientWidth;
    });
    //实现tab切换显示对应内容的逻辑
    this.requestData();
  },
  methods: {
    checkli(index) {
      this.checkindex = index;
    },
    requestData() {
      //因为没有合适的数据来源,所以假装这里就是从后端请求的所有的订单集合,在下边data中你需要吧你分类的订单根据状态进行分类。
      var orders = [
        { orderType: 3 },
        { orderType: 1 },
        { orderType: 2 },
        { orderType: 1 },
        { orderType: 3 },
        { orderType: 1 },
        { orderType: 3 },
        { orderType: 2 },
        { orderType: 2 }
      ];
      // console.log(orders)
      //把所有不同状态的订单通过if判断push到相对应的订单状态集合中
      orders.forEach(orderItem => {
        // console.log(orderItem)
        if (orderItem.orderType == 1) {//待付款
          this.pendingPayment.push(orderItem);
        }
        if (orderItem.orderType == 2) {//待收货
          this.toBeReceived.push(orderItem);
        }
        if (orderItem.orderType == 3) {//待评价
          this.beEvaluated.push(orderItem);
        }
      });
      //将所有状态下的订单集合都放到空数组中,从0-3的顺序按照自己设置的tab切换的内容0-3的顺序对应排列
      this.orderAllItem = [orders,this.pendingPayment,this.toBeReceived,this.beEvaluated]
    }
  },
  components: {
  }
};
</script>

三、css

ul.tab {
  height: 1000px;
  width: 100%;
  border-bottom: 1px solid #eeeeee;
  line-height: 1rem;
  font-size: 0.32rem;
  color: #333333;
  display: flex;
  position: relative;
  overflow: hidden;
  transition: all 0.5s;
}
.tab li {
  flex: 1;
  text-align: center;
  transition: all 0.5s;
}
.tab li.on {
  color: #da0428;
}
.tab i {
  width: 0.6rem;
  height: 0.05rem;
  border-radius: 0.03rem;
  background: #da0428;
  bottom: 0;
  position: absolute;
  transition: all 0.5s;
}

 参考网址:https://www.cnblogs.com/tis100204/p/10442455.html

Vue仿淘宝订单状态的tab切换效果——全

标签:评价   ali   ace   def   border   ack   nextTick   std   fine   

原文地址:https://www.cnblogs.com/fkcqwq/p/12892502.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!