vue封装tab切换
vue封装tab切换
预览:

第一种
通过父传子标题,子传父事件
子组件
<template>
<div class='app'>
<div class="tabs_header">
<div :class="['tabs_header_items',currentIndex==i?'active':'']" @click="itemsClick(i)" v-for="(v,i) in tabs_list"
:key="v">{{v}}</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
currentIndex: 0
};
},
props: ['tabs_list'],
methods: {
itemsClick(i) {
this.currentIndex = i
this.$emit('tabshundle', i)
}
},
};
</script>
<style scoped='scoped'>
.tabs_header {
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
.tabs_header_items {
flex: 1;
padding: 10px;
cursor: pointer;
border-bottom: 1px solid transparent;
}
.active {
color: red;
border-bottom: 1px solid red;
}
</style>
父组件
<template>
<div>
<tabs :tabs_list="tabs_list.map((v,i)=>v.title)" @tabshundle="tabshundle"></tabs>
<template v-if="currIndex==0">
<rec></rec>
</template>
<template v-else-if="currIndex==1">
<cate></cate>
</template>
<template v-else-if="currIndex==2">
<New></New>
</template>
<template v-else-if="currIndex==3">
<alb></alb>
</template>
</div>
</template>
<script>
import tabs from '../../components/tabs/tabsfb'
import alb from './alb.vue'
import cate from './cate.vue'
import New from './new.vue'
import rec from './rec.vue'
export default {
name: 'app',
data() {
return {
tabs_list: [{
title: '推荐'
},
{
title: '分类'
},
{
title: '最新'
},
{
title: '专辑'
}
],
currIndex: 0,
};
},
methods: {
tabshundle(e) {
this.currIndex = e
}
},
components: {
tabs,alb,cate,New,rec
}
};
</script>
<style scoped='scoped'>
/deep/.tabs_header {
width: 60%;
margin: 0 auto;
}
</style>
vue封装tab切换的更多相关文章
- vue 实现tab切换动态加载不同的组件
vue 实现tab切换动态加载不同的组件 使用vue中的is特性来加载不同的组件.具体看如下代码:这个功能对于vue比较复杂的页面可以使用上,可以把一个页面的功能拆分出来,使代码更简单.使用方式具体看 ...
- vue实现tab切换功能
最近用vue做一个页面的tab功能,经过一查找资料,没用路由,也没用动态组件,完美实现了tab切换功能,效果如下 下面是代码实现,这是模板 <article id="example&q ...
- VUE 实现tab切换页面效果
一 163邮箱登录tab切换 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- vue实现tab切换
需要弄类似tab切换的功能就是一个点击切换上一页下一页的页面 找到这个获得灵感 <!DOCTYPE html> <html lang="en"> <h ...
- vue -vantUI tab切换时 list组件不触发load事件解决办法
最近由于公司项目需要,用vue写了几个简单的页面.用到了vantUI List 列表 瀑布流滚动加载,用于控制长列表的展示 当列表即将滚动到底部时,会触发事件并加载更多列表项. (页面加载完成后默认会 ...
- Vue如何tab切换高亮最简易方法
以往我们实现tab切换高亮通常是循环遍历先把所有的字体颜色改变为默认样式,再点亮当前点击的选项,而我们在vue框架中实现tab切换高亮显示并不需要如此,只需要将当前点击选项的index传入给一个变量, ...
- 封装tab切换事件
HTML <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- vue实现tab切换功能精简版
<template> <div> <p class="tabs" v-for="(list,index) in lists" :c ...
- vue之tab切换
<style> .active{ color: red; } div a{ display: block; } </style> <script src="ht ...
随机推荐
- JAVA并发编程--Condition
Condition主要是为了在J.U.C框架中提供和Java传统的监视器风格的wait,notify和notifyAll方法类似的功能. AQS等待队列与Condition队列是两个相互独立的队列 a ...
- mongodb安装教程(亲测有效)
网上太多教程了,都是说的不明不白,所以自己整理一份 #参考官网: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat ...
- TIMESTAMP with implicit DEFAULT value is deprecated
出错版本 mysql 5.7 why? (警告)不包含隐式默认值的时间戳 way? 在 /etc/my.conf中 mysqld 模块中添加 explicit_defaults_for_timesta ...
- mysql-5-aggregation
#2.分组函数 /* 分组函数/聚合函数:传入一组值,经过统计处理,得到一个输出值 sum, avg, max, min, count */ USE myemployees; #简单使用 SELECT ...
- 怎样优雅的实现INotifyPropertyChanged
第一 安装nuget包 PropertyChanged.Fody. 第二 在类的上方加上 [PropertyChanged.AddINotifyPropertyChangedInterface] 类似 ...
- 【奇淫巧技】XSS绕过技巧
XSS记录 1.首先是弹窗函数: alert(1) prompt(1) confirm(1)eval() 2.然后是字符的编码和浏览器的解析机制: 要讲编码绕过,首先我们要理解浏览器的解析过程,浏览器 ...
- xor 和 or 有什么区别
参考:https://zhidao.baidu.com/question/67532331.html 1.定义区别: ①OR是或运算,A OR B的结果:当A.B中只要有一个或者两个都为1时,结果为1 ...
- c中_tmain()和main()区别
来源参考:https://www.cnblogs.com/lucyjiayou/archive/2011/05/07/2039621.html tchar.h>可以找到,如#define _tm ...
- 【CSP2019-J】游记
看我朋友们的博客里面都写了游记,我也来凑个热闹(雾) day1# 介于是\(CSP-J\),我们是比赛当天走的,上午卡点到.一路上不允许玩游戏,于是就在路上看了一路的鬼畜视频,然后看了看对拍的板子(然 ...
- Windows 系统蓝屏错误小全
0 0x00000000 作业完成. 1 0x00000001 不正确的函数. 2 0x00000002 系统找不到指定的档案. 3 0x00000003 系统找不到指定的路径. 4 0x000000 ...