Problem Description When we are working on a project, sometimes we need to make some tab bar switching effects. Some have two tabs, some have three tabs, and some even have five, six, seven or eight tabs. Normally we just use the tab component of Ele.me, but sometimes when we are free, we write one to switch between two tabs, that is, a two-choice effect. Enough of small talk, here are the dynamic renderings This case is suitable for two tabs (three tabs can be written in the same way as mine. If there are four or five tabs, it will be faster to use the Ele.me component) The code is as follows HTML Part <template> <div id="app"> <div class="tabWrap"> <!-- This structure is a tab navigation, and the corresponding click event is bound to it. In the callback of the click event, the display and hiding of the corresponding content and the modification of the style are controlled, that is, the switching of the tab--> <div class="tabNav"> <div class="navOne" @click="tabOne">tab1</div> <div class="navTwo" @click="tabTwo">tab2</div> </div> <!-- This structure is the content corresponding to the tab navigation--> <div class="tabContent"> <!-- Use v-show to control hiding, hiding one and showing one at the same time, and the tab bar switching effect is achieved--> <div class="navOneBox" v-show="showTabOne">I am switching 1</div> <div class="navTwoBox" v-show="showTabTwo">i am tab2</div> </div> </div> </div> </template> js part <script> export default { name: "app", data() { return { showTabOne: true, // Choose one of the two tabs to switch showTabTwo: false, // Choose one of the two tabs to switch }; }, methods: { //Choose one of the two tab bar switches tabOne() { /* When you click tab1, make tab1 visible and tab2 hidden, that is, showTabOne is true and showTabTwo is false At the same time, modify the style of tab1 to make it "highlighted", and be careful not to forget to modify the style of tab2 to make it "unhighlighted". The same applies when you click 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"; }, //Choose one of the two tab bar switching 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 part <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> This is the end of this article about the new implementation of Vue's two-choice tab bar switching. For more relevant Vue tab bar switching content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of the "/" problem when proxy_pass forwards according to the path path
>>: MySQL Daemon failed to start error solution
Let’s take a look at the renderings first: XML/HT...
Downloaded the unzipped version of mysql-5.6.37-w...
1. How to install? 1. [Run] -> [cmd] to open t...
Table of contents 1. Shopping cart example 2. Cod...
Table of contents 1. Commonly used string functio...
Newer Linux distributions no longer have the rc.l...
Table of contents Preface What to use if not jQue...
As the title says, otherwise when the page is revi...
Table of contents 1. mysqldump command to back up...
Table of contents Preface 1. Preparation 2. Actua...
Table of contents 1. Observable 2. Higher-order f...
Prerequisite: The web developer plugin has been in...
BMP is an image file format that is independent o...
1. Problem description <br />When JS is use...
The steps of docker packaging Python environment ...