zoukankan      html  css  js  c++  java
  • Vue仿淘宝订单状态的tab切换效果——(但现实中不会用此种方式进行存储数据)

    以下代码直接复制到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

  • 相关阅读:
    JavaScript数组API
    爱上经典之王梦麟《阿美阿美》
    爱上经典之《蜗牛与黄鹂鸟》
    爱上经典之《兰花草》
    爱上经典之《让我们看云去》
    爱上经典之卓依婷《三月里的小雨》
    爱上经典之孟庭苇《冬季到台北来看雨》
    有故事看SQA作用
    转自scmlife趣谈质量管理与工程改进面试
    Mysql之批处理
  • 原文地址:https://www.cnblogs.com/fkcqwq/p/12892502.html
Copyright © 2011-2022 走看看