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', ...
随机推荐
- 【C++11新特性】 auto关键字
原文链接: http://blog.csdn.net/xiejingfa/article/details/50469045 熟悉脚本语言的人都知道,很多脚本语言都引入了“类型自动推断”技术:比如pyt ...
- Vue基础知识之组件及组件之间的数据传递(五)
vue中的组件是自定的标签,可以扩展的原生html元素,封装可复用的代码 note: 1.在标签命中不要使用大写,标签名字必须用短横线隔开 2.模板中只能有一个根元素,不能使用并列标签. 定义组件 全 ...
- linux移动复制删除命令
用mv命令1.作用mv命令来为文件或目录改名或将文件由一个目录移入另一个目录中.该命令等同于DOS系统下的ren和move命令的组合.它的使用权限是所有用户.2.格式mv [options] 源文件或 ...
- Selenium如何定位动态id的元素?
怎么定位这类型的元素呢? 根据其他属性定位如果有其他固定属性,最先考虑的当然是根据元素的其他属性来定位,定位方式那么多,何必在这一棵树上吊死.. 根据相对关系定位根据其附近的父节点.子节点.兄弟节点定 ...
- django-template-forloop
forloop.counter0 # 是每次循环的index 红色的div标签,居然可以这样写. ex:第一次循环的结果 <div class="item active" ...
- uva146-枚举,排列
题意: 输入最多150个小写字母,在字典序增大的方向,求下一个排列是什么. 模拟枚举,最后一个字符是递归的最后一层(n层),那么把它弹出栈(还剩n-1层),如果n-1层的字符比第n层小,说明把n层的字 ...
- bootstrap3中select2的默认值和下拉框的禁用
最近做项目用到了select2插件,需求中需要给下拉框设置默认值之后,禁用下拉框,我开始的写法是这样的 <script type="text/javascript"> ...
- 如何从编程的本质理解JVM内存模型
如何从编程的本质理解JVM内存模型 一般聊JVM内存模型都是把图截出来,然后对着图,解释上面堆.栈之类的概念.这篇将分享下,如何从编程的本质上理解,JVM内存模型是什么样子,为什么是这个样子,不再死记 ...
- B站上的一个MATLAB与神经网络的视频,捡漏
▶ av15514817.这里集中了一些从视频中学到的散点. ▶ 语句 "edit + 函数名" 可以打开部分内置函数的源代码.非公开的源代码这会打开一个全是注释的文档. ▶ 函数 ...
- easyui datagrid列使用按钮的一些心得(转)
http://blog.csdn.net/sskicgah/article/details/16939959 以前,用easyui的datagrid,有时候会用到一些操作选项,比如代码如下: $('# ...