vue2.0 tab切换几种方式
第一种 比较灵活简单的方式(切换改变部分的内容在组件中比较方便操作)
<template>
<div id="app">
<ul>
<li v-for="(tab,index) in tabs" @click="toggle(index,tab.view)" :class="{active:active==index}">
{{tab.type}}
</li>
</ul>
<!--:is实现多个组件实现同一个挂载点-->
<component :is="currentView"></component>
</div>
</template> <script>
import tab1 from './components/tabs/tab1.vue'
import tab2 from './components/tabs/tab2.vue'
export default {
name: 'app',
data(){
return {
active:,
currentView:'tab1',
tabs:[
{
type:'tab1',
view:'tab1'
},
{
type:'tab2',
view:'tab2'
}
]
}
},
methods:{
toggle(i,v){
this.active=i;
this.currentView=v;
}
},
components:{
tab1,
tab2
}
}
</script> <style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
/* text-align: center;
color: #2c3e50;
margin-top: 60px; */
}
ul{
width:200px;
display:flex;
}
ul li{
width:100px;
height:40px;
background: #ccc;
display: inline-flex;
border-right:1px solid #ddd;
justify-content: center;
align-items: center;
cursor:pointer
}
ul li.active{
background:#;
}
</style>

第二种(比较死板,内容被固定住了)
<template>
<div id="app">
<ul >
<li v-for="(tab,index) in tabs" :class="{active:num==index}" @click="table(index)">{{tab}}</li>
</ul>
<div class="tabContent">
<div v-for="(tabCon,index) in tabsCon" v-show="index==num">{{tabCon}}</div>
</div>
</div>
</template> <script>
/*import tab1 from './components/tabs/tab1.vue'
import tab2 from './components/tabs/tab2.vue'*/
export default {
name: 'app',
data(){
return {
tabs:['按钮1','按钮2'],
tabsCon:['内容1','内容2'],
num:0
}
},
methods:{
table(index) {
this.num = index;
}
}
/* components:{
tab1,
tab2
}*/
}
</script> <style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
/* text-align: center;
color: #2c3e50;
margin-top: 60px; */
}
ul{
width:200px;
display:flex;
}
ul li{
width:100px;
height:40px;
background: #ccc;
display: inline-flex;
border-right:1px solid #ddd;
justify-content: center;
align-items: center;
cursor:pointer;
}
ul li.active{
background:#333;
}
</style>

第三种(比较死板,内容被固定住了,使用过jquery的人习惯用的方式)
<template>
<div id="app">
<div class="nav-tab">
<a v-for="(value,index) in tab" :class="{active:value.isactive}" @click="change(index)">
{{value.title}}
</a>
</div> <div class="tabs">
<div v-for="(value,index) in tab" class="tab" :class="{active:value.isactive}">{{value.content}}</div>
</div>
</div>
</template> <script>
/*import tab1 from './components/tabs/tab1.vue'
import tab2 from './components/tabs/tab2.vue'*/
export default {
name: 'app',
data(){
return {
tab: [{
title: 'tab1',
content: 'this is tab1',
isactive: true
}, {
title: 'tab2',
content: 'this is tab2',
isactive: false
}]
}
},
methods: {
change(index){
this.tab.forEach(function(v){
v.isactive=false
})
this.tab[index].isactive=true
}
}
}
</script> <style>
*{
padding:0;
margin:0;
box-sizing:border-box;
}
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
/* text-align: center;
color: #2c3e50;
margin-top: 60px; */
width:100%;
}
.nav-tab{
width:100%;
height: 30px;
line-height:30px;
display:flex;
justify-content: space-around;
}
.nav-tab a{
flex:1;
text-align: center;
background:#ccc;
border-right:1px solid #ddd;
cursor:pointer;
}
.nav-tab a.active{
border-bottom:1px solid red;
}
.tabs .tab{
display: none;
}
.tabs .tab.active{
display:block;
}
</style>
vue2.0 tab切换几种方式的更多相关文章
- CobalStrike 4.0 生成后门几种方式 及 主机上线后基础操作
出品|MS08067实验室(www.ms08067.com) 本文作者:BlackCat(Ms08067内网安全小组成员) CobalStrike 4.0 生成后门几种方式 步骤:Attacks-〉P ...
- MAC下安装多版本JDK和切换几种方式
环境: MAC AIR,OS X 10.10,64位 历史: 过去 Mac 上的 Java 都是由 Apple 自己提供,只支持到 Java 6,并且OS X 10.7 开始系统并不自带(而是可选 ...
- vue2.0路由切换后页面滚动位置不变BUG
最近项目中遇到这样一个问题,vue切换路由,页面到顶端的滚动距离仍会保持不变. 方法一: 监听路由 // app.vue export default { watch:{ '$route':func ...
- eclipse中英文切换--四种方式
若转载,请注明出处 http://www.cnblogs.com/last_hunter/p/5627009.html 谢谢! ------------------------------------ ...
- Win8 安装.Net Framework3.5(2.0,3.0)组件二种方式
第一种: 通过命令+win8映像文件 找到系统盘cmd文件:C:\WINDOWS\system32\Cmd.exe 右键“以管理员身份运行”,然后弹出一个黑框框. 黑框框里面输入一下命令: dism. ...
- vue2.0 动态切换组件
组件标签是Vue框架自定义的标签,它的用途就是可以动态绑定我们的组件,根据数据的不同更换不同的组件. <!DOCTYPE html> <html lang="en" ...
- Vue2.0的三种常用传值方式、父传子、子传父、非父子组件传值
参考链接:https://blog.csdn.net/lander_xiong/article/details/79018737
- Vue2.0 $set()的正确使用方式
https://blog.csdn.net/panyang01/article/details/76665448
- drupal7 覆写node-type.tpl.php获取字段值的两种方式
字段的机读名称为:field_publication_date <!-- 下面两种方式都可以获取node字段的值--> 出版时间: <?php print date('Y-m-d', ...
随机推荐
- 学习MongoDB 四: MongoDB查询(一)
一.简介 MongoDB提供了db.collection.find() 方法可以实现根据条件查询和指定使用投影运算符返回的字段省略此参数返回匹配文档中的所有字段. 二.db.collection.fi ...
- multiprocess模块---进程---进程队列
首先明白几个概念: 同步:做完一件事情,再做另外一件事情 异步:做一件事情的时候,可以再做另外一件事情 阻塞:recv sleep accept input recvfrom 非阻塞:没有遇见上面这 ...
- DEMO: springboot 与 mybatis 集成
之前一直在用springMVC,接触到springboot之后,感觉使用起来方便多了,没那多xml需要配置. 先来看看整个项目结构,当然是maven项目. 1.测试数据 DROP TABLE IF E ...
- java垃圾回收几种算法
1.引用计数法 2.标记——清除法 3.标记——整理算法 4.copying算法 5.generation算法(新生代.老年代.持久代) 详情参考:深入理解 Java 垃圾回收机制
- 前端-HTML练习题
本小节重点: 熟练使用div+span布局,知道div和span的语义化的意思 熟悉对div.ul.li.span.a.img.table.form.input标签有深刻的认知,初期也了解他们,知道他 ...
- something about facebook token
There are two method origin token , you can use any one of them, first one may be easier. Origin fro ...
- jstatd - Virtual Machine jstat Daemon
jstatd [options] 参数:options 命令行参数,可以按任何顺序,但如果有多余的或者中有互斥的参数,最后制定的那个参数将有优先权 options: -nr 当一个存在的RMI Reg ...
- 如何在Oracle中建立表和表空间?
1.建表空间 ORACLE中,表空间是数据管理的基本方法,所有用户的对象要存放在表空间中,也就是用户有空间的使用权,才能创建用户对象.否则是不充许创建对象,因为就是想创建对象,如表,索引等,也没有地方 ...
- Docker-删除untagged docker images
故障描述 [root@entel1 ~]# docker rmi entel_zmc_images:zmc_base Untagged: entel_zmc_images:zmc_base 操作步骤 ...
- jQuery中的几个模块总结
Query插件,以备并希望在前端方面有所长进.请批评指正. 一,类型判断全解 JQuery判断类型扩展方法:$.type() /*type: function( obj ) { if ( obj == ...