ion-Tabs
Tab là thành phần điều hướng cấp cao nhất để triển khai điều hướng dựa trên tab. Thành phần là một vùng chứa riêng lẻ các tabs components .
Thành phần ion-tabs không có bất kỳ kiểu dáng nào và hoạt động như một ổ cắm bộ định tuyến để xử lý điều hướng. Nó không cung cấp bất kỳ phản hồi hoặc cơ chế giao diện người dùng nào để chuyển đổi giữa các tab. Để làm như vậy, một ion-tab-bar phải được cung cấp với tư cách là con trực tiếp của ion-tabs.
Cả hai ion-tabs và ion-tab-bar có thể được sử dụng như các phần tử độc lập. Chúng không phụ thuộc vào nhau để hoạt động, nhưng chúng thường được sử dụng cùng nhau để triển khai điều hướng dựa trên tab hoạt động giống như một ứng dụng gốc.
Các ion-tab-bar cần một khe được xác định để được dự kiến đến đúng địa chỉ trong một ion-tabs thành phần.
Usage
<ion-tabs>
<ion-tab-bar slot="bottom">
<ion-tab-button tab="schedule">
<ion-icon name="calendar"></ion-icon>
<ion-label>Schedule</ion-label>
<ion-badge>6</ion-badge>
</ion-tab-button>
<ion-tab-button tab="speakers">
<ion-icon name="person-circle"></ion-icon>
<ion-label>Speakers</ion-label>
</ion-tab-button>
<ion-tab-button tab="map">
<ion-icon name="map"></ion-icon>
<ion-label>Map</ion-label>
</ion-tab-button>
<ion-tab-button tab="about">
<ion-icon name="information-circle"></ion-icon>
<ion-label>About</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>Router integration
When used with Angular's router the tab property of the ion-tab-button should be a reference to the route
path.<ion-tabs>
<ion-tab-bar slot="bottom">
<ion-tab-button tab="schedule">
<ion-icon name="calendar"></ion-icon>
<ion-label>Schedule</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>import { Routes } from '@angular/router';
import { TabsPage } from './tabs-page';
const routes: Routes = [
{
path: 'tabs',
component: TabsPage,
children: [
{
path: 'schedule',
children: [
{
path: '',
loadChildren: '../schedule/schedule.module#ScheduleModule'
}
]
},
{
path: '',
redirectTo: '/app/tabs/schedule',
pathMatch: 'full'
}
]
}
];<ion-tabs>
<ion-tab tab="tab-schedule">
<ion-nav></ion-nav>
</ion-tab>
<ion-tab tab="tab-speaker">
<ion-nav></ion-nav>
</ion-tab>
<ion-tab tab="tab-map" component="page-map">
<ion-nav></ion-nav>
</ion-tab>
<ion-tab tab="tab-about" component="page-about">
<ion-nav></ion-nav>
</ion-tab>
<ion-tab-bar slot="bottom">
<ion-tab-button tab="tab-schedule">
<ion-icon name="calendar"></ion-icon>
<ion-label>Schedule</ion-label>
<ion-badge>6</ion-badge>
</ion-tab-button>
<ion-tab-button tab="tab-speaker">
<ion-icon name="person-circle"></ion-icon>
<ion-label>Speakers</ion-label>
</ion-tab-button>
<ion-tab-button tab="tab-map">
<ion-icon name="map"></ion-icon>
<ion-label>Map</ion-label>
</ion-tab-button>
<ion-tab-button tab="tab-about">
<ion-icon name="information-circle"></ion-icon>
<ion-label>About</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>Activating Tabs
Mỗi ion-tab-buttontab sẽ kích hoạt một trong các tab khi được nhấn. Để liên kết ion-tab-buttonvới ion-tabcontainer, một kết hợp tabtài sản phải được thiết lập trên mỗi thành phần.
<ion-tab tab="settings">
...
</ion-tab>
<ion-tab-button tab="settings">
...
</ion-tab-button>Các ion-tab-buttonvà ion-tabtrên được liên kết bởi tabtài sản chung .
Các tabbất động sản xác định mỗi tab, và nó phải là duy nhất trong ion-tabs. Điều quan trọng là luôn đặt thuộc tabtính trên ion-tabvà ion-tab-button, ngay cả khi một thành phần không được sử dụng.
Router integration
Khi được sử dụng với bộ định tuyến của Ionic ( ion-router), thuộc tabtính của ion-tabđối sánh với thuộc componenttính của an ion-route.
Lộ trình sau trong phạm vi của một ion-tabscửa hàng:
<ion-route url="/settings-page" component="settings"></ion-route>sẽ khớp với tab sau:
<ion-tab tab="settings" component="settings-component"></ion-tab>import React from 'react';
import { IonTabs, IonTabBar, IonTabButton, IonIcon, IonLabel, IonBadge } from '@ionic/react';
import { calendar, personCircle, map, informationCircle } from 'ionicons/icons';
export const TabsExample: React.FC = () => (
<IonTabs>
<IonTabBar slot="bottom">
<IonTabButton tab="schedule">
<IonIcon icon={calendar} />
<IonLabel>Schedule</IonLabel>
<IonBadge>6</IonBadge>
</IonTabButton>
<IonTabButton tab="speakers">
<IonIcon icon={personCircle} />
<IonLabel>Speakers</IonLabel>
</IonTabButton>
<IonTabButton tab="map">
<IonIcon icon={map} />
<IonLabel>Map</IonLabel>
</IonTabButton>
<IonTabButton tab="about">
<IonIcon icon={informationCircle} />
<IonLabel>About</IonLabel>
</IonTabButton>
</IonTabBar>
</IonTabs>
);import { Component, h } from '@stencil/core';
@Component({
tag: 'tabs-example',
styleUrl: 'tabs-example.css'
})
export class TabsExample {
render() {
return [
<ion-tabs>
<ion-tab tab="tab-schedule">
<ion-nav></ion-nav>
</ion-tab>
<ion-tab tab="tab-speaker">
<ion-nav></ion-nav>
</ion-tab>
<ion-tab tab="tab-map" component="page-map">
<ion-nav></ion-nav>
</ion-tab>
<ion-tab tab="tab-about" component="page-about">
<ion-nav></ion-nav>
</ion-tab>
<ion-tab-bar slot="bottom">
<ion-tab-button tab="tab-schedule">
<ion-icon name="calendar"></ion-icon>
<ion-label>Schedule</ion-label>
<ion-badge>6</ion-badge>
</ion-tab-button>
<ion-tab-button tab="tab-speaker">
<ion-icon name="person-circle"></ion-icon>
<ion-label>Speakers</ion-label>
</ion-tab-button>
<ion-tab-button tab="tab-map">
<ion-icon name="map"></ion-icon>
<ion-label>Map</ion-label>
</ion-tab-button>
<ion-tab-button tab="tab-about">
<ion-icon name="information-circle"></ion-icon>
<ion-label>About</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
];
}
}Activating Tabs
Mỗi ion-tab-buttontab sẽ kích hoạt một trong các tab khi được nhấn. Để liên kết ion-tab-buttonvới ion-tabcontainer, một kết hợp tabtài sản phải được thiết lập trên mỗi thành phần.
<ion-tab tab="settings">
...
</ion-tab>
<ion-tab-button tab="settings">
...
</ion-tab-button>Các ion-tab-buttonvà ion-tabtrên được liên kết bởi tabtài sản chung .
Các tabbất động sản xác định mỗi tab, và nó phải là duy nhất trong ion-tabs. Điều quan trọng là luôn đặt thuộc tabtính trên ion-tabvà ion-tab-button, ngay cả khi một thành phần không được sử dụng.
Router integration
Khi được sử dụng với bộ định tuyến của Ionic ( ion-router), thuộc tabtính của ion-tabđối sánh với thuộc componenttính của an ion-route.
Lộ trình sau trong phạm vi của một ion-tabscửa hàng:
<ion-route url="/settings-page" component="settings"></ion-route>sẽ khớp với tab sau:
<ion-tab tab="settings" component="settings-component"></ion-tab>Tabs.vue
<template>
<ion-page>
<ion-tabs @ionTabsWillChange="beforeTabChange" @ionTabsDidChange="afterTabChange">
<ion-tab-bar slot="bottom">
<ion-tab-button tab="schedule" href="/tabs/schedule">
<ion-icon :icon="calendar"></ion-icon>
<ion-label>Schedule</ion-label>
<ion-badge>6</ion-badge>
</ion-tab-button>
<ion-tab-button tab="speakers" href="/tabs/speakers">
<ion-icon :icon="personCircle"></ion-icon>
<ion-label>Speakers</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
</ion-page>
</template>
<script>
import { defineComponent } from 'vue';
import {
IonIcon,
IonLabel,
IonPage,
IonTabBar,
IonTabButton,
IonTabs
} from '@ionic/vue';
import { calendar, personCircle } from 'ionicons/icons';
export default defineComponent({
components: { IonIcon, IonLabel, IonPage, IonTabBar, IonTabButton, IonTabs },
setup() {
const beforeTabChange = () => {
// do something before tab change
}
const afterTabChange = () => {
// do something after tab change
}
return {
calendar,
personCircle,
beforeTabChange,
afterTabChange
}
}
});
</script>Schedule.vue
<template>
<ion-page>
<ion-header>
<ion-toolbar>
<ion-title>Schedule</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">Schedule Tab</ion-content>
</ion-page>
</template>
<script>
import { defineComponent } from 'vue';
import {
IonContent,
IonHeader,
IonPage,
IonTitle,
IonToolbar
} from '@ionic/vue';
export default defineComponent({
components: { IonContent, IonHeader, IonPage, IonTitle, IonToolbar }
});
</script>Speakers.vue
<template>
<ion-page>
<ion-header>
<ion-toolbar>
<ion-title>Speakers</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">Speakers Tab</ion-content>
</ion-page>
</template>
<script>
import { defineComponent } from 'vue';
import {
IonContent,
IonHeader,
IonPage,
IonTitle,
IonToolbar
} from '@ionic/vue';
export default defineComponent({
components: { IonContent, IonHeader, IonPage, IonTitle, IonToolbar }
});
</script>Events
| Name | Description |
|---|---|
ionTabsDidChange | Emitted when the navigation has finished transitioning to a new component. |
ionTabsWillChange | Emitted when the navigation is about to transition to a new component. |
Methods
getSelected | |
|---|---|
| Description | Get the currently selected tab. |
| Signature | getSelected() => Promise<string | undefined> |
getTab | |
| Description | Get a specific tab by the value of its |
| Signature | getTab(tab: string | HTMLIonTabElement) => Promise<HTMLIonTabElement | undefined> |
select | |
| Description | Select a tab by the value of its |
| Signature | select(tab: string | HTMLIonTabElement) => Promise<boolean> |
Slots
| Name | Description |
|---|---|
| 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. |
ion-tab
Thành phần tab là một thành phần con của các tab. Mỗi tab có thể chứa ngăn xếp điều hướng cấp cao nhất cho một ứng dụng hoặc một chế độ xem. Một ứng dụng có thể có nhiều tab, tất cả đều có điều hướng độc lập của riêng chúng.
Properties
component | |
|---|---|
| Description | The component to display inside of the tab. |
| Attribute | component |
| Type | Function | HTMLElement | null | string | undefined |
tab | |
| Description | A tab id must be provided for each |
| Attribute | tab |
| Type | string |
Methods
setActive | |
|---|---|
| Description | Set the active component for the tab |
| Signature | setActive() => Promise<void> |
ion-tab-bar
Thanh tab là một thành phần giao diện người dùng chứa một tập hợp các tab buttons. Một thanh tab phải được cung cấp bên trong các Tabs giao tiếp với mỗi tab.
Usage
<ion-tabs>
<!-- Tab bar -->
<ion-tab-bar slot="bottom">
<ion-tab-button tab="account">
<ion-icon name="person"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="contact">
<ion-icon name="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="settings">
<ion-icon name="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs><ion-tabs>
<!-- Tab views -->
<ion-tab tab="account"></ion-tab>
<ion-tab tab="contact"></ion-tab>
<ion-tab tab="settings"></ion-tab>
<!-- Tab bar -->
<ion-tab-bar slot="bottom">
<ion-tab-button tab="account">
<ion-icon name="person"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="contact">
<ion-icon name="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="settings">
<ion-icon name="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>import React from 'react';
import { IonTabs, IonTabBar, IonTabButton, IonIcon, IonContent } from '@ionic/react';
import { call, person, settings } from 'ionicons/icons';
export const TabBarExample: React.FC = () => (
<IonContent>
<IonTabs>
{/*-- Tab bar --*/}
<IonTabBar slot="bottom">
<IonTabButton tab="account">
<IonIcon icon={person} />
</IonTabButton>
<IonTabButton tab="contact">
<IonIcon icon={call} />
</IonTabButton>
<IonTabButton tab="settings">
<IonIcon icon={settings} />
</IonTabButton>
</IonTabBar>
</IonTabs>
</IonContent>
);import { Component, h } from '@stencil/core';
@Component({
tag: 'tab-bar-example',
styleUrl: 'tab-bar-example.css'
})
export class TabBarExample {
render() {
return [
<ion-tabs>
{/* Tab views */}
<ion-tab tab="account" component="page-account"></ion-tab>
<ion-tab tab="contact" component="page-contact"></ion-tab>
<ion-tab tab="settings" component="page-settings"></ion-tab>
{/* Tab bar */}
<ion-tab-bar slot="bottom">
<ion-tab-button tab="account">
<ion-icon name="person"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="contact">
<ion-icon name="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="settings">
<ion-icon name="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
];
}
}<template>
<ion-tabs>
<!-- Tab bar -->
<ion-tab-bar slot="bottom">
<ion-tab-button tab="account">
<ion-icon :icon="person"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="contact">
<ion-icon :icon="call"></ion-icon>
</ion-tab-button>
<ion-tab-button tab="settings">
<ion-icon :icon="settings"></ion-icon>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
</template>
<script>
import { IonIcon, IonTabBar, IonTabButton, IonTabs } from '@ionic/vue';
import { call, person, settings } from 'ionicons/icons';
import { defineComponent } from 'vue';
export default defineComponent({
components: { IonIcon, IonTabBar, IonTabButton, IonTabs },
setup() {
return { call, person, settings }
}
});
</script>Properties
color | |
|---|---|
| Description | The color to use from your application's color palette. Default options are: |
| Attribute | color |
| Type | string | undefined |
mode | |
| Description | The mode determines which platform styles to use. |
| Attribute | mode |
| Type | "ios" | "md" |
selectedTab | |
| Description | The selected tab component |
| Attribute | selected-tab |
| Type | string | undefined |
translucent | |
| Description | If |
| Attribute | translucent |
| Type | boolean |
| Default | false |
Css Custom Properties
| Name | Description |
|---|---|
--background | Background of the tab bar |
--border | Border of the tab bar |
--color | Color of the tab bar |
ion-tab-button
Nút tab là một thành phần giao diện người dùng được đặt bên trong tab bar. Nút tab có thể chỉ định bố cục của biểu tượng và nhãn và kết nối với tan View
Usage
<ion-tabs>
<!-- Tab bar -->
<ion-tab-bar slot="bottom">
<ion-tab-button tab="schedule">
<ion-icon name="calendar"></ion-icon>
<ion-label>Schedule</ion-label>
</ion-tab-button>
<ion-tab-button tab="speakers">
<ion-icon name="person-circle"></ion-icon>
<ion-label>Speakers</ion-label>
</ion-tab-button>
<ion-tab-button tab="map">
<ion-icon name="map"></ion-icon>
<ion-label>Map</ion-label>
</ion-tab-button>
<ion-tab-button tab="about">
<ion-icon name="information-circle"></ion-icon>
<ion-label>About</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs><ion-tabs>
<!-- Tab views -->
<ion-tab tab="schedule">
<ion-router-outlet name="schedule"></ion-router-outlet>
</ion-tab>
<ion-tab tab="speakers">
<ion-router-outlet name="speakers"></ion-router-outlet>
</ion-tab>
<ion-tab tab="map">
<ion-router-outlet name="map"></ion-router-outlet>
</ion-tab>
<ion-tab tab="about">
<ion-router-outlet name="about"></ion-router-outlet>
</ion-tab>
<!-- Tab bar -->
<ion-tab-bar slot="bottom">
<ion-tab-button tab="schedule" href="/app/tabs/(schedule:schedule)">
<ion-icon name="calendar"></ion-icon>
<ion-label>Schedule</ion-label>
</ion-tab-button>
<ion-tab-button tab="speakers" href="/app/tabs/(speakers:speakers)">
<ion-icon name="person-circle"></ion-icon>
<ion-label>Speakers</ion-label>
</ion-tab-button>
<ion-tab-button tab="map" href="/app/tabs/(map:map)">
<ion-icon name="map"></ion-icon>
<ion-label>Map</ion-label>
</ion-tab-button>
<ion-tab-button tab="about" href="/app/tabs/(about:about)">
<ion-icon name="information-circle"></ion-icon>
<ion-label>About</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>import React from 'react';
import { IonTabs, IonTabBar, IonTabButton, IonIcon, IonLabel, IonContent } from '@ionic/react';
import { calendar, personCircle, map, informationCircle } from 'ionicons/icons';
export const TabButtonExample: React.FC = () => (
<IonContent>
<IonTabs>
{/*-- Tab bar --*/}
<IonTabBar slot="bottom">
<IonTabButton tab="schedule">
<IonIcon icon={calendar} />
<IonLabel>Schedule</IonLabel>
</IonTabButton>
<IonTabButton tab="speakers">
<IonIcon icon={personCircle} />
<IonLabel>Speakers</IonLabel>
</IonTabButton>
<IonTabButton tab="map">
<IonIcon icon={map} />
<IonLabel>Map</IonLabel>
</IonTabButton>
<IonTabButton tab="about">
<IonIcon icon={informationCircle} />
<IonLabel>About</IonLabel>
</IonTabButton>
</IonTabBar>
</IonTabs>
</IonContent>
);import { Component, h } from '@stencil/core';
@Component({
tag: 'tab-button-example',
styleUrl: 'tab-button-example.css'
})
export class TabButtonExample {
render() {
return [
<ion-tabs>
{/* Tab views */}
<ion-tab tab="schedule">
<ion-router-outlet name="schedule"></ion-router-outlet>
</ion-tab>
<ion-tab tab="speakers">
<ion-router-outlet name="speakers"></ion-router-outlet>
</ion-tab>
<ion-tab tab="map">
<ion-router-outlet name="map"></ion-router-outlet>
</ion-tab>
<ion-tab tab="about">
<ion-router-outlet name="about"></ion-router-outlet>
</ion-tab>
{/* Tab bar */}
<ion-tab-bar slot="bottom">
<ion-tab-button tab="schedule" href="/app/tabs/(schedule:schedule)">
<ion-icon name="calendar"></ion-icon>
<ion-label>Schedule</ion-label>
</ion-tab-button>
<ion-tab-button tab="speakers" href="/app/tabs/(speakers:speakers)">
<ion-icon name="person-circle"></ion-icon>
<ion-label>Speakers</ion-label>
</ion-tab-button>
<ion-tab-button tab="map" href="/app/tabs/(map:map)">
<ion-icon name="map"></ion-icon>
<ion-label>Map</ion-label>
</ion-tab-button>
<ion-tab-button tab="about" href="/app/tabs/(about:about)">
<ion-icon name="information-circle"></ion-icon>
<ion-label>About</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
];
}
}<template>
<ion-tabs>
<!-- Tab bar -->
<ion-tab-bar slot="bottom">
<ion-tab-button tab="schedule" href="/tabs/schedule">
<ion-icon :icon="calendar"></ion-icon>
<ion-label>Schedule</ion-label>
</ion-tab-button>
<ion-tab-button tab="speakers" href="/tabs/speakers">
<ion-icon :icon="person-circle"></ion-icon>
<ion-label>Speakers</ion-label>
</ion-tab-button>
<ion-tab-button tab="map" href="/tabs/map">
<ion-icon :icon="map"></ion-icon>
<ion-label>Map</ion-label>
</ion-tab-button>
<ion-tab-button tab="about" href="/tabs/about">
<ion-icon :icon="informationCircle"></ion-icon>
<ion-label>About</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
</template>
<script>
import {
IonIcon,
IonLabel,
IonTabBar,
IonTabButton,
IonTabs
} from '@ionic/vue';
import { calendar, informationCircle, map, personCircle } from 'ionicons/icons';
import { defineComponent } from 'vue';
export default defineComponent({
components: {
IonIcon,
IonLabel,
IonTabBar,
IonTabButton,
IonTabs
},
setup() {
return { calendar, informationCircle, map, personCircle }
}
});
</script>Properties
disabled | |
|---|---|
| Description | If |
| Attribute | disabled |
| Type | boolean |
| Default | false |
download | |
| Description | This attribute instructs browsers to download a URL instead of navigating to it, so the user will be prompted to save it as a local file. If the attribute has a value, it is used as the pre-filled file name in the Save prompt (the user can still change the file name if they want). |
| Attribute | download |
| Type | string | undefined |
href | |
| Description | Contains a URL or a URL fragment that the hyperlink points to. If this property is set, an anchor tag will be rendered. |
| Attribute | href |
| Type | string | undefined |
layout | |
| Description | Set the layout of the text and icon in the tab bar. It defaults to |
| Attribute | layout |
| Type | "icon-bottom" | "icon-end" | "icon-hide" | "icon-start" | "icon-top" | "label-hide" | undefined |
mode | |
| Description | The mode determines which platform styles to use. |
| Attribute | mode |
| Type | "ios" | "md" |
rel | |
| Description | Specifies the relationship of the target object to the link object. The value is a space-separated list of link types. |
| Attribute | rel |
| Type | string | undefined |
selected | |
| Description | The selected tab component |
| Attribute | selected |
| Type | boolean |
| Default | false |
tab | |
| Description | A tab id must be provided for each |
| Attribute | tab |
| Type | string | undefined |
target | |
| Description | Specifies where to display the linked URL. Only applies when an |
| Attribute | target |
| Type | string | undefined |
CSS Shadow parts
| Name | Description |
|---|---|
native | The native HTML anchor element that wraps all child elements. |
CSS Custom Properties
| Name | Description |
|---|---|
--background | Background of the tab button |
--background-focused | Background of the tab button when focused with the tab key |
--background-focused-opacity | Opacity of the tab button background when focused with the tab key |
--color | Color of the tab button |
--color-focused | Color of the tab button when focused with the tab key |
--color-selected | Color of the selected tab button |
--padding-bottom | Bottom padding of the tab button |
--padding-end | Right padding if direction is left-to-right, and left padding if direction is right-to-left of the tab button |
--padding-start | Left padding if direction is left-to-right, and right padding if direction is right-to-left of the tab button |
--padding-top | Top padding of the tab button |
--ripple-color | Color of the button ripple effect |

0 Nhận xét