content

<template>
<div class="tab-content">
<TabBar v-model="activeKey">
<TabBody label="标签一" name="1">
标签一的内容
</TabBody>
<TabBody label="标签二" name="2">
标签二的内容
</TabBody>
<TabBody label="标签三" name="3">
标签三的内容
</TabBody>
<TabBody label="标签四" name="4">
标签四的内容
</TabBody>
</TabBar>
</div>
</template> <script> import TabBar from '@/components/TabBar';
import TabBody from '@/components/TabBody'; export default {
name:"tabContent",
data() {
return{
activeKey:'1'
}
},
components:{
TabBar,
TabBody
} }
</script> <style lang="less">
.tab-header{
display: flex;
justify-content: center;
align-items: center;
line-height: 30px;
.tabs-item{
border-right: 1px solid #eee;
padding: 0 10px;
&:last-child{
border-right: 0;
}
}
}
.tab-content{
padding: 10px;
}
</style>

tabbar

<template>
<div class="tab-bar">
<div class="tab-header">
<div class="tabs-item"
:class="tabCls(item)"
v-for="(item,idx) in navList"
:key="idx"
@click="handlerChange(idx)"
>
{{item.label}}
</div> </div> <div class="tab-body">
<slot></slot>
</div>
</div>
</template> <script>
export default {
props:{
value:{
type:[String,Number]
}
},
data(){
return{
currentValue:this.value,
navList:[]
}
},
methods:{
tabCls(item){
return [
'tabs-tab',
{
'tabs-active':item.name == this.currentValue
}
]
},
handlerChange(idx){
let nav = this.navList[idx];
let name = nav.name;
this.currentValue = name;
this.$emit('input',name)
this.$emit('on-click',name);
},
getTabs(){
return this.$children.filter((item)=>{
return item.$options.name == 'pane'
})
},
updateNav(){
this.navList = [];
this.getTabs().forEach((pane,idx)=>{
this.navList.push({
label:pane.label,
name:pane.name || idx
})
if(!pane.name){
pane.nam = idx;
}
if(idx == 0){
if(!this.currentValue){
this.currentValue == pane.name || idx;
}
}
})
this.updateStatus();
},
updateStatus(){
let tabs = this.getTabs();
tabs.forEach(item=>{
return item.show = item.name === this.currentValue;
})
}
},
watch:{
value(val){
this.currentValue = val;
},
currentValue(){
this.updateStatus();
}
}
}
</script> <style> </style>

tab-body

<template>
<div class="tab-content" v-show="show">
<slot></slot>
</div>
</template> <script>
export default {
name:'pane',
props:{
name:{
type:String
},
label:{
type:String,
default:''
}
},
data() {
return{
show:true
}
},
methods:{
updateNav(){
this.$parent.updateNav();
}
},
mounted(){
this.updateNav();
},
watch:{
label(){
this.updateNav();
}
}
}
</script> <style> </style>

最新文章

  1. 我所理解的SOA和微服务
  2. java二维数组的常见初始化
  3. Visual Studio 2010(.NET 4.0)中使用SQLite.NET
  4. hiho_1081_最短路径1
  5. 初识 AutoLayout
  6. sql语句中BEGIN TRAN...COMMIT TRAN
  7. MVC日期格式化的2种方式
  8. Android 服务_笔记
  9. 使用nginx处理静态资源请求,其余交给node
  10. An SDN-NFV Platform for Personal Cloud Services
  11. 前端基础之JS
  12. gcc编译基本用法~1
  13. vue中的一些知识点--多看文档
  14. 自适应Simpson法与积分初步
  15. 404错误处理以及以后缀为action结尾的处理
  16. xagrs 指定参数位置
  17. poj 3414 Pots(广搜BFS+路径输出)
  18. Oracle PL/SQL学习之基础篇(1)
  19. Python多线程1:threading
  20. 160504、springmvc返回json数据编码格式设定

热门文章

  1. [2019BUAA软工助教]第0次个人作业
  2. Java多线程-线程池ThreadPoolExecutor构造方法和规则
  3. Python——Twisted框架(网络通信)
  4. 使用System.out.printf()输出日志重定向到文件后显示混乱问题
  5. 在Ubuntu上使用离线方式快速安装K8S v1.11.1
  6. [powershell]解决Win7SP1 powershell底色变成黑色
  7. 初识 go 语言:数据类型
  8. request param 获取
  9. Oracle 获取前几行数据问题的陷阱
  10. 小米平板2 win10 MIUI互刷教程