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

<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. relocation error: /usr/lib64/libc.so.6: symbol _dl_starting_up, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference 问题解决

    在建立一个错误的软连接到ld-linux-x86-64.so.2时,悲剧就这么发生了.此时大部分命令都不能使用,SSH当然也不能登录了.这个时候一定不要退出终端. 有人说那就把软连接复原吧,可是ln也 ...

  2. 单例模式(Singleton)

    单例模式  Singletonn Pattern Ensure a class has only one instance, and provide  a global point of access ...

  3. ATM+购物商城

    知识内容: 1.luffy买tesla 2.ATM+购物商城 一.luffy买tesla 需求: 1.目录结构说明 account luffy.json --> 存储用户账户信息 {" ...

  4. 原生socket请求url获取状态码、消息报头、响应正文

    需求: (1)使用socket及ssl模块写通用的web客户端 (2)向服务器发起请求 (3)接受响应内容并解析出状态码.消息报头.响应正文 (4)最核心的函数: 输入一个url,返回状态码.消息报头 ...

  5. 3.纯 CSS 创作一个容器厚条纹边框特效

    原文地址:3.纯 CSS 创作一个容器厚条纹边框特效 没有啥好点子呀,不爽 HTML代码: <div class="box"> <div class=" ...

  6. C#_Markov_心得感想

    来到实验室正好有一个月了,趁着端午假期稍微轻松一些,在大改程序体系之前,想将自己在这30天中工作之一Markov回顾一下,将从真实的写程序中学习到的知识.思想记录下来.希望能和大家积极讨论! 本文会以 ...

  7. C# WEB.API 接收并解析保存base64格式的图片

    using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System. ...

  8. WINRAR 自解压脚本命令及变量

    自解压脚本命令 Path=d:\ ;绝对路径 ;Path=.\在当前文件夹中创建 ;Path=在“Program Files”中创建 ;在当前文件夹创建,无语句 Setup=释放后运行 Presetu ...

  9. curl 请求https内容,返回空

    $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$api); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);/ ...

  10. ActiveMQ无法启动

    解决办法:activemq无法启动,端口被占用 用netstat -an无法查出61616被哪个进程占用(实践证明,netstat -ano|findstr '61616'什么也没有找到) 经过排查和 ...