目录

tab-bar

Overview

Functions as a subelement of tabs. Tab bars appear horizontally and allow users to switch among different sections of an app.

Application Scope

Item

Description

Applicable devices

Mobile phones, tablets, and telematics devices

Applicable regions

Global

Subelements

Supported.

Attributes

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

Attribute

Type

Default Value

Mandatory

Description

mode

scrollable | fixed

fixed

No

  • When mode is set to scrollable, subelements can be scrolled horizontally if the width of all subelements is greater than the width of the tab bar.
  • When mode is set to fixed, the width of the tab bar is evenly divided into the width of subelements regardless of whether the width of all subelements is greater than the width of the tab bar.

Styles

In addition to common styles, the style listed in the following table is supported.

Style

Type

Default Value

Mandatory

Description

height

length | percentage

100px

No

Height.

Events

Common events (excluding swipe) are supported.

Sample Code

<template>
  <div class="container">
    <div class="page-title-wrap">
      <text class="page-title">{{componentName}}</text>
    </div>
    <tabs class="tabs" onchange="changeTabactive" index="2">
      <tab-bar class="tab-bar">
        <text class="tab-text">basic</text>
        <text class="tab-text">form</text>
        <text class="tab-text">list</text>
      </tab-bar>
    </tabs>
  </div>
</template>

<style>
  .container {
    flex: 1;
    flex-direction: column;
  }
  .page-title-wrap {
    padding-top: 50px;
    padding-bottom: 80px;
    justify-content: center;
  }
  .page-title {
    padding-top: 30px;
    padding-bottom: 30px;
    padding-left: 40px;
    padding-right: 40px;
    border-color: #bbbbbb;
    color: #bbbbbb;
    border-bottom-width: 2px;
  }
  .tabs {
    flex: 1;
    margin-top: 20px;
    margin-right: 30px;
    margin-left: 30px;
    background-color: #ffffff;
  }

  .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;
  }
</style>

<script>
  import prompt from '@system.prompt'

  export default {
    data: {
      componentName: 'tabs',
    },
    onInit: function () {
      this.$page.setTitleBar({ text: 'tab-bar' })

    },
    changeTabactive: function (e) {
      prompt.showToast({
        message: "the playing page number is " + e.index +"  "
      })
      // switch tab
      console.log('----------switch tab: ' + e.index)
    },
  }
</script>

The following figure shows the final effect.