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