目录

tabs

Overview

Functions as a tab container.

Application Scope

Item

Description

Applicable devices

Mobile phones, tablets, and telematics devices

Applicable regions

Global

Subelements

A tabs element can wrap at most one tab-bar element and one tab-content element. Currently, tab-content cannot be dynamically added. Otherwise, the content may be incorrect.

Attributes

In addition to general attributes, the attribute listed in the following table is supported.

Attribute

Type

Default Value

Mandatory

Description

index

number

0

No

Index of the active tab.

Styles

Common styles are supported.

Events

In addition to common events (excluding swipe), the event listed in the following table is supported.

Event

Parameter

Triggering Condition

change

{index: indexValue}

The active tab changes.

Sample Code

<template>
    <div class="container">
        <tabs class="tabs" onchange="changeTabactive" index="2">
            <tab-bar class="tab-bar">
                <text class="tab-text">tab1</text>
                <text class="tab-text">tab2</text>
                <text class="tab-text">tab3</text>
            </tab-bar>
            <tab-content class="tab-content" scrollable="{{scrollable}}">
                <div class="item-container">
                    <div class="item-content">
                        <text class="item-title">tab1 page</text>
                    </div>
                </div>
                <div class="item-container">
                    <div class="item-content">
                        <text class="item-title">tab2 page</text>
                    </div>
                </div>
                <div class="item-container">
                    <div class="item-content">
                        <text class="item-title">tab3 page</text>
                    </div>
                </div>
            </tab-content>
        </tabs>
    </div>
</template>
<style>
    .tabs {
        flex: 1;
        margin-top: 20px;
        margin-right: 30px;
        margin-left: 30px;
        background-color: #ffffff;
    }
    .tab-content {
        flex: 1;
    }
    .tab-bar {
        height: 100px;
        border-color: #bbbbbb;
        color: #bbbbbb;
        border-bottom-width: 1px;
    }
    .tab-text {
        width: 300px;
        text-align: center;
    }
    .tab-text:active {
        color: #f76160;
    }
    .item-container {
        padding-top: 30px;
        padding-left: 30px;
        padding-right: 30px;
        flex-direction: column;
    }
    .item-content {
        flex-direction: column;
        padding-bottom: 30px;
    }
    .item-title {
        padding-top: 50px;
        padding-bottom: 20px;
        color: #aaaaaa;
    }
</style>
<script>
    import prompt from '@system.prompt'
    export default {
        data: {
            scrollable: true,
        },
        onInit: function () {
            this.$page.setTitleBar({ text: 'tabs' })
        },
        changeTabactive: function (e) {
            prompt.showToast({
                message: this.$t('message.component.tabs.range') + e.index + this.$t('message.component.tabs.page')
            })
            // switch tab
            console.log('----------switch tab: ' + e.index);
        },
    }
</script>

The following figure shows the final effect.

Links

[h2]FAQ

How can I implement the function of changing the tab style when the tab pages are switched?

[h2]Cases