tabs组件

<template>
<view class="tabs">
<view class="bar" :style="barStyle"><view class="inner"></view></view>
<view v-for="(it, index) of tabs" :key="it" class="item" :class="{ active: active === index }" @click="onClick(index, $event)">
<text>{{ it }}</text>
</view>
</view>
</template> <script>
export default {
name: 'my-tabs',
props: {
tabs: {
type: Array,
default: () => []
}, // 选中默认index
active: {
type: Number,
default: 0
}
},
data() {
return {
barStyle: {
transform: 'translateX(0%)'
}
};
},
methods: {
onClick(index, $event) {
this.$emit('onClick', index);
if (index !== this.active) {
this.$emit('onChange', index);
}
}
},
watch: {
tabs: {
handler: function(val) {
this.barStyle.width = `${100 / val.length}%`;
},
immediate: true
},
active: {
handler: function(val) {
// animated
this.barStyle.transform = `translateX(${val * 100}%)`;
},
immediate: true
}
}
};
</script> <style lang="stylus" scoped>
.tabs
position relative
display flex
align-items center
background-color #fff
.item
display flex
flex 1
align-items center
justify-content center
padding 30rpx
font-size 30rpx
transition ease 0.3s
&.active
color red
transition color ease 0.3s
.bar
position absolute
left 0
bottom 0
height 6rpx
transition transform ease 0.3s
display flex
align-items center
justify-content center
.inner
width 100%
height 100%
box-sizing border-box
margin 0 20rpx
border-radius 18rpx
background-color red
</style>

使用

    <myTabs :tabs="tabs" :active="active" @onChange="active = $event"></myTabs>
<view v-if="active == 0" class="list1">list1</view>
<view v-if="active == 1" class="list2">list2</view> import myTabs from '@/shared/widgets/my-tabs.vue';
export default {
components: { myTabs },
data() {
return {
tabs: ['t0', 't1'],
active: 0
};
},
methods: {}
};

uniapp 创建简单的tabs的更多相关文章

  1. [.NET] WebApi 生成帮助文档及顺便自动创建简单的测试工具

    ==========最终的效果图========== ==========下面开始干活:生成帮助文档========== 一.创建 WebApi 项目 二.找到 HelpPageConfig.cs 并 ...

  2. Web Service 的创建简单编码、发布和部署

    最近,老大准备将已有的C/S架构项目中的通信部分做成通用,需要将其支持WebService为以后项目向着B/S架构升级做好铺垫,为此身为屌丝的我去各种百度WebService是个什么卵玩意,然后逐渐搭 ...

  3. Azure PowerShell (5) 使用Azure PowerShell创建简单的Azure虚拟机和Linux虚拟机

    <Windows Azure Platform 系列文章目录> 本文介绍的是国外的Azure Global.如果是国内由世纪互联运维的Azure China,请参考这篇文档: Azure ...

  4. myeclipse(2015)中创建简单的Maven项目的步骤(用于生成可执行jar文件)------》myeclipse2015

    利用MyEclipse的引导,可以很方便的创建简单的.用于生成可执行jar文件的Maven项目: 1.New -> Project... 选择 Maven Project, 点击Next > ...

  5. 使用Visual Studio创建简单的自己定义Web Part 部件属性

    使用Visual Studio创建简单的自己定义Web Part 部件属性 自己定义属性使用额外的选项和设置拓展你的Web part部件.本文主要解说怎样使用Visual Studio创建简单的自己定 ...

  6. C链表之创建简单静态链表

    C代码: #include<stdio.h> #include<stdlib.h> #include<malloc.h> //创建简单静态链表 typedef st ...

  7. 使用Visual Studio 2010 创建简单的Silverlight应用程序

    使用Visual Studio 2010 创建简单的Silverlight应用程序 Silverlight是创建动态的引人的RIAs(Rich Internet Application)的新方法.这里 ...

  8. 创建简单的响应式HTML5模版

    创建简单的响应式HTML5模版 HTML5目前发展势头良好,已经逐渐得到大部分浏览器不同程度的支持.许多web开发者也已经学习到了不少关于HTML 5的基础知识并开始试图使用HTML 5制作网页.与此 ...

  9. django初探-创建简单的博客系统

    django第一步 1. django安装 pip install django print(django.get_version()) 查看django版本 2. 创建项目 打开cmd,进入指定目录 ...

随机推荐

  1. Redis 学习笔记系列文章之 Redis 的安装与配置 (一)

    1. 介绍 Redis is an open source (BSD licensed), in-memory data structure store, used as database, cach ...

  2. 题解 P1248 【加工生产调度】

    题目 某工厂收到了 n 个产品的订单,这 n 个产品分别在 A.B 两个车间加工,并且必须先在 A 车间加工后才可以到 B 车间加工. 某个产品 i 在 A.B 两车间加工的时间分别为 Ai,Bi 怎 ...

  3. Spring Cloud系列之Commons - 1. 背景与基础知识准备

    本文基于 Spring Cloud 2020.0 发布版的依赖 本系列会深入分析 Spring Cloud 的每一个组件,从Spring Cloud Commons这个 Spring Cloud 所有 ...

  4. 封装SpringJdbcTemplate

    package com.jy.modules.cms.query; import java.util.List; import java.util.Map; public interface quer ...

  5. 提升NginxTLS/SSL HTTPS 性能的7条优化建议

    自2018年7月起,谷歌浏览器开始将" HTTP"网站标记为"不安全".在过去的几年中,互联网已经迅速过渡到HTTPS,Chrome浏览器的流量超过70%,并且 ...

  6. JMM和volatile

    1.volatile 2.JMM 3.代码示例 package com.yanshu; class MyNmuber{ volatile int number=10; public void addT ...

  7. vs中python包安装教程

    vs安装python很简单,只需要在vs安装包中选择python就可以了,这里使用的python3.7: 如果有了解,都知道安装python包的指令:"pip install xxx&quo ...

  8. 2015 German Collegiate Programming Contest (GCPC 15) + POI 10-T3(12/13)

    $$2015\ German\ Collegiate\ Programming\ Contest\ (GCPC 15) + POI 10-T3$$ \(A.\ Journey\ to\ Greece\ ...

  9. uva10859 Placing Lampposts (树形dp+求两者最小值方法)

    题目链接:点击打开链接 题意:给你一个n个点m条边的无向无环图,在尽量少的节点上放灯,使得所有边都被照亮,每盏灯将照亮以它为一个端点的所有边.在灯的总数最小的前提下,被两盏灯同时照亮的边数应尽量大. ...

  10. hdu1625 Numbering Paths (floyd判环)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission ...