<template>
<div id="demo31">
<p>-----------------组件基础之动态tab组件一---------------------</p>
<button
v-for="tab in tabs"
v-bind:key="tab"
v-bind:class="['tab-button', { active: currentTab === tab }]"
v-on:click="currentTab = tab"
>{{ tab }}</button> <component v-bind:is="currentTabComponent" class="tab"></component>
</div>
</template> <script>
export default {
components: {
tabhome: {
template: "<div>Home component<div>"
},
tabpost: {
template: "<div>Posts component<div>"
},
tabarchive: {
template: "<div>Archive component<div>"
}
},
data() {
return {
currentTab: "Home",
tabs: ["Home", "Post", "Archive"]
};
},
computed: {
currentTabComponent() {
return "tab" + this.currentTab.toLowerCase();
}
}
};
</script>
<style>
.tab-button {
padding: 6px 10px;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
border: 1px sollid #ccc;
cursor: pointer;
background: #f0f0f0;
margin-bottom: -1px;
margin-right: -1px;
}
.tab-button:hover {
background: #e0e0e0;
}
.tab-button .active {
background: #e0e0e0;
}
.tab {
border: 1px solid #ccc;
padding: 10px;
}
</style>

demo2:

<template>
<div id="demo32">
<p>-----------------组件基础之动态tab组件二---------------------</p>
<button
v-for="(tab,index) in tabs"
v-bind:key="index"
v-bind:class="['tab-button', { active: currentIndex === index }]"
v-on:click="currentIndex = index"
>{{ tab }}</button> <component v-bind:is="currentTabComponent" class="tab"></component>
</div>
</template> <script>
export default {
components: {
tab_home: {
template: "<div>Home component<div>"
},
tab_post: {
template: "<div>Posts component<div>"
},
tab_archive: {
template: "<div>Archive component<div>"
}
},
data() {
return {
currentIndex:0,
tabs: ["Home", "Post", "Archive"]
};
},
computed: {
currentTabComponent() {
return 'tab_'+this.tabs[this.currentIndex].toLowerCase()
}
}
};
</script>
<style>
.tab-button {
padding: 6px 10px;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
border: 1px sollid #ccc;
cursor: pointer;
background: #f0f0f0;
margin-bottom: -1px;
margin-right: -1px;
}
.tab-button:hover {
background: #e0e0e0;
}
.tab-button .active {
background: #e0e0e0;
}
.tab {
border: 1px solid #ccc;
padding: 10px;
}
</style>

https://blog.csdn.net/kingrome2017/article/details/80541680  vuejs2.0 组件基础动态组件 Tab选项卡插件

最新文章

  1. 关于Struts2上传文件的最大Size的设置
  2. IEBrowse学习笔记
  3. 基于requirejs+bluebird,50行代码实现轻巧实用的前端CMD加载器
  4. css3整理-方便查询使用
  5. Bean的自动装配
  6. Django REST framework 第五章 Relationships &amp; Hyperlinked APIs
  7. centos环境gcc版本升级
  8. scala mysql jdbc oper
  9. free结果解释
  10. POJ 2369 Permutations(置换群概念题)
  11. 实验八 Web基础
  12. linux 添加elasticsearch 开机重启(自启动)
  13. mongodb常用操作命令(待续)
  14. 插入排序之python
  15. 学习Android Studio里的Gradle
  16. weblogic之CVE-2016-3510反序列化分析
  17. HP G7服务器添加新硬盘
  18. [ python ] 项目二:主机批量管理程序
  19. java 实现图片拼接
  20. Django 内建 中间件组件

热门文章

  1. SAP UI5应用入口App.controller.js是如何被UI5框架加载的?
  2. 07 Windows编程——窗口滚动条
  3. 一分钟了解Linux文件系统
  4. Array 和 ArrayList 有何区别?(未完成)
  5. Java&amp;Selenium自动化测试调用JS实现单击
  6. HBuilderX 5+APP MUI 入门
  7. unittest简单使用的介绍
  8. 前端知识体系:JavaScript基础-原型和原型链-理解 es6 中class构造以及继承的底层实现原理
  9. 27-SQLServer系统扩展存储过程
  10. postgresql backup