用Vue自定义实现Tab
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://unpkg.com/vue/dist/vue.js"></script>
</head>
<style type="text/css">
.odm-tab {
margin: 20px;
padding: 0px;
border: 1px solid #e2e2e2;
text-align: left !important;
}
.odm-tab-title {
background-color: #f2f2f2;
border-bottom: 1px solid #e2e2e2;
}
.odm-tab-title ul {
width: 200px;
padding: 0;
line-height: 40px;
height: 40px;
box-sizing: border-box;
}
.odm-tab-title ul li {
min-width: 65px;
display: inline-block;
text-align: center;
vertical-align: middle;
font-size: 14px;
padding: 0 10px;
height: 41px !important;
list-style: none;
margin-right: -1px;
margin-left: -1px;
line-height: 40px;
box-sizing: border-box;
}
.odm-tab-title ul li:hover {
cursor: pointer;
}
.odm-tab-title ul li.active {
background: #FFF;
height: 100%;
color: #39f;
transition: color .3s ease-in-out;
border: 1px solid #e2e2e2;
border-bottom-color: #fff;
box-sizing: border-box !important;
pointer-events: none;
border-top: none;
border-width: 1px;
border-bottom-color: #fff;
}
.odm-tab-content {
padding: 10px;
}
.odm-tab-content-item {
padding: 10px;
}
</style>
<div id="app" class="odm-tab">
<div class="odm-tab-title">
<ul>
<li @click="toggleTabs(0)" :class="{active:nowIndex === 0}">Tab1</li>
<li @click="toggleTabs(1)" :class="{active:nowIndex === 1}">Tab2</li>
</ul>
</div>
<div class="odm-tab-content">
<div class="odm-tab-content-item" v-show="nowIndex === 0">我是tab1</div>
<div class="odm-tab-content-item" v-show="nowIndex === 1">我是tab2</div>
</div>
</div>
<script>
var app=new Vue({
el:'#app',
data:{
nowIndex:0
},
methods:{
toggleTabs:function(index){
this.nowIndex=index;
},
}
})
</script>
</body>
</html>
运行效果: