vue tab标签

sx122 2020-03-24 原文

vue tab标签

最近做个项目,需要像淘宝秒杀页那样的tab标签,可滑动可点击的,就自己做了个组件记录一下

<template>
  <div class="tab" :style="{background:background}" ref="scroll">
    <div class="navCon" :style="{width:width*nav.length+'px',height:height+'px'}">
      <div
        v-for="(item, index) in nav"
        :key="index"
        class="navList"
        :style="{width:width+'px'}"
        @click="toLeft(index)"
      >
        <p
          :style="{color:index==pitch?active_color:color,'font-size':sizi+'px',height:list_1.length?'50%':'100%'}"
          class="title"
        >
          <span>{{item}}</span>
        </p>
        <p class="title1" v-if="list_1.length">
          <span>{{list_1[index]}}</span>
        </p>
      </div>
    </div>
  </div>
</template>
export default {
  data() {
    return {
      pitch:this.active
    };
  },
  props: {
    nav:{
      type: Array,
      default: ()=>{
        return ["标签一","标签二","标签三","标签四","标签五","标签六","标签七","标签八"]
      }
    },
    active: {
      //唯一标识符
      type: Number,
      default: 0
    },
    background: {
      //背景颜色
      type: String,
      default: "red"
    },
    width: {
      //
      type: String,
      default: "76"
    },
    active_color: {
      // 选中字体颜色
      type: String,
      default: "#fff"
    },
    color: {
      // 字体颜色
      type: String,
      default: "#ccc"
    },
    sizi: {
      // 字体大小一
      type: String,
      default: "16"
    },
    list_1: {
      // 数据列表
      type: Array,
      default: function() {
        return [];
      }
    },
    height: {
      //
      type: String,
      default: "44"
    }
  },
  created() {
    this.$nextTick(() => {
      if (this.active > 2 && this.active <= this.nav.length - 3) {
        this.$refs.scroll.scrollLeft = (this.active - 2) * this.width;
      }
    });
  },
  mounted() {},
  methods: {
    toLeft(index) {
      this.pitch=index
        this.$emit('change',index)
      if (index <= 2) {
        this.$refs.scroll.scrollLeft = "0";
        return;
      } else if (index >= this.nav.length - 3) {
        this.$refs.scroll.scrollLeft = this.width * (this.nav.length - 3);
      } else {
        this.$refs.scroll.scrollLeft = this.width * (index - 2);
      }
    }
  }
};
</script>
<style scoped>
.tab {
  width: 100%;
  height: 88px;
  overflow-y: scroll;
}
::-webkit-scrollbar {
  display: none;
}
.navCon {
  height: 100%;
}
.navList {
  float: left;
  height: 100%;
}
.title {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.title1 {
  width: 100%;
  height: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
</style>

 —-最后希望大神指点指点—-

发表于
2020-03-24 15:34 
sx122 
阅读(
评论(
编辑 
收藏

 

版权声明:本文为sx122原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/sx122/p/12559289.html

vue tab标签的更多相关文章

  1. 仵航说 Vue用replace修改数组中对象的键值或者字段名 仵老大

    仵航说 Vue用replace修改数组中对象的键值或者字段名 仵老大 1.介绍 先看图 ​ 今天在项目中遇到了 […]...

  2. ES6中用&&跟||来简化if{}else{}的写法

    目录 ES6中用&&跟||来简化if{}else{}的写法 1. if else的写法 2. […]...

  3. react router @4 和 vue路由 详解(一)vue路由基础和使用

    1、vue路由基础和使用   a、大概目录            我这里建了一个router文件夹,文件夹下有 […]...

  4. 3.vue引入axios全局配置

    前言: Vue官方推荐使用axios来进行异步访问。 axios文档参考:axios中文文档 开始搭建: 1. […]...

  5. vue+element——父级元素fixed,遮罩会在上方

    前言   这种场景还是蛮场景的   一个共用的head组件,组件里面通常是当前系统登录账号名 退出登录 修改密 […]...

  6. 前端国际化的实现(5种情景的中英文)

      最近做国外项目,需要实现项目的的国际化,这里大致捋一下思路、实现方式。项目技术栈是  vue + antd […]...

  7. Vue 批量注册局部组件及应用

    博客地址:https://ainyi.com/105 批量注册路由的有个博客说到:https://ainyi. […]...

  8. 关于 node build/build.js 卡顿的问题

    今天也是奇了怪了,npm run dev 可以正常执行,但node build/build.js  就死活不行 […]...

随机推荐

  1. 更换HomeBrew源

      比较少用brew,只有之前安装Opencv的时候用过一次,后面有人问我怎么装,于是帮他研究了一下。MacO […]...

  2. 使用多域名SSL证书 一种免费的证书申请方式

    众所周知,目前都在推行是有SSL证书的网站,也就是我们的网站使用HTTPS://方式访问,这样的访问将会更加安 […]...

  3. Android智能手机上的音频浅析

    手机可以说是现在人日常生活中最离不开的电子设备了。它自诞生以来,从模拟的发展到数字的,从1G发展到目前的4G以 […]...

  4. 装错MacOS驱动遇四国,简单步骤告别重装

    目前Mac系统已经很容易装上,至于AMD,只是时间问题。所谓苹果难啃,难在驱动,没有完美驱动的系统等于有辆名牌 […]...

  5. Win7 下面查看当前端口对应的进程名字(XP同样适用)

    Win7 下面查看当前端口对应的进程名字。 一直以来习惯了使用 Active Port1.4来查看当前程序占用 […]...

  6. WebSpher 6.1 安装与应用

    1. 名词术语解释1.1 名词缩写:1、 WAS: 即IBM公司的应用服务器WebSphere Applica […]...

  7. 管理运筹学 指派问题答案

    ...

  8. RFC2616-HTTP1.1-Methods(方法规定部分—译文)

    part of Hypertext Transfer Protocol — HTTP/1.1RFC […]...

展开目录

目录导航