WeChat applet implementation tab function, WeChat applet Tab

Source: Internet
Author: User

Applet implementation tab function, Applet Tab

The examples in this article share the code displayed by the applet tab function for your reference. The details are as follows:

First, let's take a look at the effect of tabs on the Applet:

The principle is to layout it first (you don't have to talk about it), define the same Click Event on each of the tabs above, and then bind a unique identifier to each component, then, when an event is triggered, the bound identifier is obtained to determine which tab is currently clicked, and then to determine which tab is shown below. The code is displayed:

Wxml:

<view class="menu_box"> <text class='menu1 {{menuTapCurrent=="0"?"borders":""}}' data-current="0" catchtap="menuTap">menu1</text> <text class='menu2 {{menuTapCurrent=="1"?"borders":""}}' data-current="1" catchtap="menuTap">menu2</text></view><view class="tab1" hidden="{{menuTapCurrent!='0'}}">tab1</view><view class="tab2" hidden="{{menuTapCurrent!='1'}}">tab2</view>

Wxss:

.menu_box{ display: flex; height: 80rpx;}.menu1,.menu2{ flex: 1; font-size:30rpx; line-height: 80rpx; text-align: center;}.borders{ border-bottom: 4rpx solid #f00; color: #f00;}.tab1,.tab2{ height: 300rpx; background: #23bff3;}.tab2{ background: #ccc;}

JS:

MenuTap: function (e) {var current = e. currentTarget. dataset. current; // obtain the bound data // change the value of menuTapCurrent to the data bound to the currently selected menu this. setData ({menuTapCurrent: current });},

End.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.