当前位置: 首页 > 工具软件 > Tab Accordian > 使用案例 >

使用vue简单实现tab选项卡切换效果分享

李飞翼
2023-12-01
<style scoped>
	.menu{
	    display: flex;
	    align-items: center;
	}
	.menu span{
	    color: #444950;
	    font-size: 12px;
	    line-height: 24px;
	    background: #f5f6f7;
	    padding: 0 6px;
	    display: block;
	    cursor: pointer;
	}
	.show{
	    color: #fff !important;
	    background: #1877f2 !important;
	}
</style>

<div class="menu">
    <span @click="btn(1)" :class="{show:tab === 1}">菜单一</span>
    <span @click="btn(2)" :class="{show:tab === 2}">菜单二</span>
    <span @click="btn(3)" :class="{show:tab === 3}">菜单三</span>
</div>
<div class="content">
    <span v-if="tab == 1">内容一</span>
    <span v-if="tab == 2">内容二</span>
    <span v-if="tab == 3">内容三</span>
</div>

<script>
	export default {
	  data () {
	    return {
	      tab: 1
	    }
	  },
	  methods: {
	    btn (key) {
	        this.tab = key
	    }
	  }
	}
</script>
 类似资料: