vue二选一tab栏切换怎样做?简单tab栏切换效果详解
Admin 2021-04-28 群英技术资讯 1871 次浏览

HTML部分
<template>
<div id="app">
<div class="tabWrap">
<!-- 这个结构是tab导航,并给其绑定对应的点击事件,在点击事件的回调中
去控制对应内容的显示隐藏和样式的修改即:tab的切换-->
<div class="tabNav">
<div class="navOne" @click="tabOne">tab1</div>
<div class="navTwo" @click="tabTwo">tab2</div>
</div>
<!-- 这个结构是tab导航对应的内容 -->
<div class="tabContent">
<!-- 通过v-show控制隐藏,同一时刻隐藏一个显示一个,就实现了tab栏的切换效果了 -->
<div class="navOneBox" v-show="showTabOne">我是切换1</div>
<div class="navTwoBox" v-show="showTabTwo">i am tab2</div>
</div>
</div>
</div>
</template>
js部分
<script>
export default {
name: "app",
data() {
return {
showTabOne: true, // 二选一tab切换
showTabTwo: false, // 二选一tab切换
};
},
methods: {
// 二选一tab栏切换
tabOne() {
/*
点击tab1的时候,让tab1显示,tab2隐藏,即showTabOne为true,showTabTwo为false
同时修改tab1的样式使其"高亮",注意不要忘了修改tab2的样式,使其"不高亮"。
点击tab2的时候,也是同理。
*/
this.showTabOne = true;
this.showTabTwo = false;
document.querySelector(".navOne").style.backgroundColor = "#fff";
document.querySelector(".navTwo").style.backgroundColor = "#e3e3e3";
document.querySelector(".navOne").style.color = "#3985EC";
document.querySelector(".navTwo").style.color = "#80868D";
},
// 二选一tab栏切换
tabTwo() {
this.showTabTwo = true;
this.showTabOne = false;
document.querySelector(".navOne").style.backgroundColor = "#e3e3e3";
document.querySelector(".navTwo").style.backgroundColor = "#fff";
document.querySelector(".navTwo").style.color = "#3985EC";
document.querySelector(".navOne").style.color = "#80868D";
},
},
};
</script>
css部分
<style lang="less">
.tabNav {
width: 126px;
height: 30px;
border-radius: 2px;
background-color: #e3e3e3;
display: flex;
align-items: center;
justify-content: space-evenly;
.navOne {
width: 60px;
height: 26px;
border-radius: 2px;
background-color: #fff;
color: #3985ec;
font-size: 14px;
font-weight: 500;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
.navTwo {
width: 60px;
height: 26px;
color: #80868d;
border-radius: 2px;
font-size: 14px;
font-weight: 500;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}
}
.tabContent {
margin-top: 8px;
.navOneBox {
background-color: #bfa;
}
.navTwoBox {
background-color: #baf;
}
}
</style>
以上就是关于实现vue二选一tab栏切换效果的代码介绍,如果是三个选型大家可以参考上述代码来实现,更多选择项的使用组件比较快,希望本文对大家有帮助。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
Javascript 完全套用了 Java 的位运算符,包括按位与&、按位或|、按位异或^、按位非~、左移<<、带符号的右移>>和用0补足的右移>>>。这套运算符针对的是整数,所以对 JavaScript 完全无用,因为 JavaScript 内部,所有数字都保存为双精度浮点数。
这篇文章主要为大家详细介绍了js实现轮播图自动切换,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
JavaScript中移除onclick事件的方法是什么?在JavaScript中想要移除onclick事件,首先我们需要获取元素对象,然后元素对象.onclick=null语句就能实现了。文中的示例代码介绍得很详细,有需要的朋友可以参考,接下来就跟随小编一起了解看看吧。
这篇文章主要介绍了利用JS创建一个录屏功能,创建这个功能钱我们首先创建一个HTML文件,包含记录按钮和一个播放标签,下面来看看创建的详细过程
这篇文章主要为大家详细介绍了jquery实现简单的弹窗效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008