第一种 比较灵活简单的方式(切换改变部分的内容在组件中比较方便操作)

<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切换几种方式的更多相关文章

  1. CobalStrike 4.0 生成后门几种方式 及 主机上线后基础操作

    出品|MS08067实验室(www.ms08067.com) 本文作者:BlackCat(Ms08067内网安全小组成员) CobalStrike 4.0 生成后门几种方式 步骤:Attacks-〉P ...

  2. MAC下安装多版本JDK和切换几种方式

    环境: MAC AIR,OS X 10.10,64位   历史: 过去 Mac 上的 Java 都是由 Apple 自己提供,只支持到 Java 6,并且OS X 10.7 开始系统并不自带(而是可选 ...

  3. vue2.0路由切换后页面滚动位置不变BUG

    最近项目中遇到这样一个问题,vue切换路由,页面到顶端的滚动距离仍会保持不变.  方法一: 监听路由 // app.vue export default { watch:{ '$route':func ...

  4. eclipse中英文切换--四种方式

    若转载,请注明出处 http://www.cnblogs.com/last_hunter/p/5627009.html 谢谢! ------------------------------------ ...

  5. Win8 安装.Net Framework3.5(2.0,3.0)组件二种方式

    第一种: 通过命令+win8映像文件 找到系统盘cmd文件:C:\WINDOWS\system32\Cmd.exe 右键“以管理员身份运行”,然后弹出一个黑框框. 黑框框里面输入一下命令: dism. ...

  6. vue2.0 动态切换组件

    组件标签是Vue框架自定义的标签,它的用途就是可以动态绑定我们的组件,根据数据的不同更换不同的组件. <!DOCTYPE html> <html lang="en" ...

  7. Vue2.0的三种常用传值方式、父传子、子传父、非父子组件传值

    参考链接:https://blog.csdn.net/lander_xiong/article/details/79018737

  8. Vue2.0 $set()的正确使用方式

    https://blog.csdn.net/panyang01/article/details/76665448

  9. drupal7 覆写node-type.tpl.php获取字段值的两种方式

    字段的机读名称为:field_publication_date <!-- 下面两种方式都可以获取node字段的值--> 出版时间: <?php print date('Y-m-d', ...

随机推荐

  1. Phoenix 安装完的几个简单使用

    Phoenix 安装完之后的一些简单使用: 本屌丝的运行环境是3节点集群,先启动hadoop,每个节点分别启动zookeeper,启动hbase(具体怎么启动这里就不多说了) 进入 phoenix的b ...

  2. Salesforce开源TransmogrifAI:用于结构化数据的端到端AutoML库

    AutoML 即通过自动化的机器学习实现人工智能模型的快速构建,它可以简化机器学习流程,方便更多人利用人工智能技术.近日,软件行业巨头 Salesforce 开源了其 AutoML 库 Transmo ...

  3. 显示锁(一)Lock显示锁的优点

    转载自 Java 并发:Lock 框架详解 摘要: 我们已经知道,synchronized 是java的关键字,是Java的内置特性,在JVM层面实现了对临界资源的同步互斥访问,但 synchroni ...

  4. python实现定时发送系列

    1.发送邮件实现 2.定时任务实现 3.定时发送邮件实现 4.微信定时发送信息 详细源代码见:https://github.com/15387062910/timing_send 参考: 廖雪峰博客 ...

  5. python之列表操作

    1.列表的增操作(四种) append(object):append object to end,directly used on list insert(index,object):insert o ...

  6. nms

    nms函数是保留选框中得分最高的那一个 Python代码如下 def nms(boxes, threshold, method): """ boxes: [x1, y1, ...

  7. 最近学习下,nohup和&的区别

    nohup是永久执行 &是指在后台运行 运行 nohup --helpRun COMMAND, ignoring hangup signals. 可以看到是“运行命令,忽略挂起信号” 就是指, ...

  8. DevExpress.XtraEditors.Groupcontrol 中创建按钮

    1. 添加引用: Imports DevExpress.XtraEditors.ButtonsPanelControl 2. 添加按钮语句: GroupControl1.CustomHeaderBut ...

  9. Activity服务类-8 RuntimeService服务类

    一共89个接口1.启动流程实例(20个方法)//使用给定的键在流程定义的最新版本中启动一个新的流程实例.ProcessInstance startProcessInstanceByKey(String ...

  10. 如何给echarts图表添加下载图表成图片的功能

    先打开一个现成的图表效果图,注意图中圈出的地方,如图   打开源码找到option,如图   在option下添加toolbox,如图   在toolbox下添加feature,如图   在featu ...