Uniapp's method to implement the tab function: first write an outer frame, fix the tab at the top and use [display: flex]; then use ternary operation to assign a sort respectively, and if selected, add [inv- h-se] style; finally write two different containers and use [v-show] to switch.
The operating environment of this tutorial: windows7 system, uni-app2.5.1 version, Dell G3 computer.
Uniapp's method of implementing the tab function:
Step instructions:
1. First write an outer frame, then write 2 contents, first Fix the tab at the top using display: flex
;, and then write 2 different styles to distinguish between selected and unselected
2. Use ternary operation to assign a sort to them respectively, click When getting the first or second one, if selected, add the inv-h-se style
3. The first one is displayed by default in the return
4. Finally, write 2 different container, use v-show
to switch
<template> <view> <view class="inv-h-w"> <view :class="['inv-h',Inv==0?'inv-h-se':'']" @click="Inv=0">选项卡1</view> <view :class="['inv-h',Inv==1?'inv-h-se':'']" @click="Inv=1">我是选项卡二</view> </view> <view class="" v-show="Inv == 0"> 我是选项卡一 </view> <view class="" v-show="Inv == 1"> 我是选项卡二 </view> </view> </template> <script> export default { data() { return { Inv:0 } }, methods: { changeTab(Inv){ that.navIdx = Inv; }, } } </script> <style> .inv-h-w{background-color: #FFFFFF;height: 100upx;display: flex;} .inv-h{font-size: 30upx;flex: 1;text-align: center;color: #C9C9C9;height: 100upx;line-height: 100upx;} .inv-h-se{color: #5BA7FF;border-bottom: 4upx solid #5BA7FF;} page{background-color: #F2F2F2;} </style>
The effect is as shown:
##Related free learning recommendations:
The above is the detailed content of How uniapp implements tab function. For more information, please follow other related articles on the PHP Chinese website!

The article discusses debugging strategies for mobile and web platforms, highlighting tools like Android Studio, Xcode, and Chrome DevTools, and techniques for consistent results across OS and performance optimization.

The article discusses debugging tools and best practices for UniApp development, focusing on tools like HBuilderX, WeChat Developer Tools, and Chrome DevTools.

The article discusses end-to-end testing for UniApp applications across multiple platforms. It covers defining test scenarios, choosing tools like Appium and Cypress, setting up environments, writing and running tests, analyzing results, and integrat

The article discusses various testing types for UniApp applications, including unit, integration, functional, UI/UX, performance, cross-platform, and security testing. It also covers ensuring cross-platform compatibility and recommends tools like Jes

The article discusses common performance anti-patterns in UniApp development, such as excessive global data use and inefficient data binding, and offers strategies to identify and mitigate these issues for better app performance.

The article discusses using profiling tools to identify and resolve performance bottlenecks in UniApp, focusing on setup, data analysis, and optimization.

The article discusses strategies for optimizing network requests in UniApp, focusing on reducing latency, implementing caching, and using monitoring tools to enhance application performance.

The article discusses optimizing images in UniApp for better web performance through compression, responsive design, lazy loading, caching, and using WebP format.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use
