返回介绍

Ionic4 底部Tabs组件组件 ion-tabs

发布于 2019-11-22 18:04:18 字数 5968 浏览 1546 评论 0 收藏 0

Ionic4项目中我们可以使用Ionic4底部Tabs组件组件ion-tabs对项目进行布局。

ion-tabs官方文档地址:https://ionicframework.com/docs/api/tabs

Tabs are a top level navigation component to implement a tab-based navigation. The component is a container of individual Tab components.

ion-tabs is a styleless component that works as a router outlet in order to handle navigation. This component does not provide any UI feedback or mechanism to switch between tabs. In order to do so, an ion-tab-bar should be provided as a direct child of ion-tabs:


  Home Content
  Settings Content

  

    
      Home
      
      6
    

    
      Settings
      
    

  
</ion-tabs>

Note that both ion-tabs and ion-tab-bar can be used as standalone elements. They don’t depend on each other to work, but they are usually used together in order to implement a tab-based navigation that feels like a native app.

ion-tab-bar always needs slot="bottom" in order to be projected into ion-tabs at the right place.

The "tab" property

Each ion-tab-button will activate one of the tabs when tapped. In order to link the button to the ion-tab container, a matching tab property must be used.


[...]
<ion-tab-button tab="settings">

This ion-tab-button and ion-tab are now linked by the common tab property.

The tab property identifies each tab, and it has to be unique within the scope of the same ion-tabs. It's important to set the same property to ion-tab and ion-tab-button, even if you are only using one. e.g. You could use the ion-tab-bar without using ion-tabs. In this case you should still give each ion-tab the property of tab="something".

Router integration

When the ionic's router (ion-router) is used, the tab property matches the "component" of ion-route:

The following route within the scope of a ion-tabs outlet:

</ion-route>

Would match the following tab:

</ion-tab>

Angular Router integration

Using tabs with Angular's router is fairly straight forward. Here you only need to define tab which is the reference to the route.



  
    
      
      Schedule
    
  
</ion-tabs>

ion-tabs 用法(Usage)


  
    
      
      Schedule
      6
    

    
      
      Speakers
    

    
      
      Map
    

    
      
      About
    
  
</ion-tabs>


  
    
  

  
    
  

  
    
  

  
    
  

  
    
      
      Schedule
      6
    

    
      
      Speakers
    

    
      
      Map
    

    
      
      About
    
  

</ion-tabs>
import React from 'react';

import { IonTabs, IonTabBar, IonTabButton, IonIcon, IonLabel, IonBadge } from '@ionic/react';

const Example: React.SFC = () => (

  
    
      
        
        Schedule
        6
      

      
        
        Speakers
      

      
        
        Map
      

      
        
        About
      
    
  
);

export default Example;

  
  
    
      
    

    
    
      
    

    
    
      
    

    
    
      
    

    
    
      
        
          
          Schedule
          6
        

        
        
          
          Speakers
        

        
        
          
          Map
        

        
        
          
          About
        
      
    
  
</template>

ion-tabs 事件(Events)

NameDescription
ionTabsDidChangeEmitted when the navigation has finished transitioning to a new component.
ionTabsWillChangeEmitted when the navigation is about to transition to a new component.

ion-tabs 内置方法(Methods)

getSelected

Description

Get the currently selected tab.

SignaturegetSelected() => Promise<string | undefined>

getTab

Description

Get a specific tab by the value of its tab property or an element reference.

SignaturegetTab(tab: string | HTMLIonTabElement) => Promise<HTMLIonTabElement | undefined>

select

Description

Select a tab by the value of its tab property or an element reference.

Signatureselect(tab: string | HTMLIonTabElement) => Promise<boolean>

Slots

NameDescription
Content is placed between the named slots if provided without a slot.
"bottom"Content is placed at the bottom of the screen.
"top"Content is placed at the top of the screen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文