ion-menu
Thành phần Menu là một ngăn điều hướng trượt vào từ một bên của dạng xem hiện tại. Theo mặc định, nó trượt vào từ bên trái, nhưng bên có thể bị ghi đè. Menu sẽ được hiển thị khác nhau tùy theo chế độ, tuy nhiên kiểu hiển thị có thể được thay đổi thành bất kỳ loại menu nào có sẵn. Phần tử menu phải là anh em ruột với phần tử nội dung gốc. Có thể có bất kỳ số lượng menu nào được đính kèm với nội dung. Chúng có thể được kiểm soát từ các mẫu hoặc lập trình bằng MenuController.
Usage
<ion-menu side="start" menuId="first" contentId="main">
<ion-header>
<ion-toolbar color="primary">
<ion-title>Start Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-menu side="start" menuId="custom" contentId="main" class="my-custom-menu">
<ion-header>
<ion-toolbar color="tertiary">
<ion-title>Custom Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-menu side="end" type="push" contentId="main">
<ion-header>
<ion-toolbar color="danger">
<ion-title>End Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-router-outlet id="main"></ion-router-outlet>import { Component } from '@angular/core';
import { MenuController } from '@ionic/angular';
@Component({
selector: 'menu-example',
templateUrl: 'menu-example.html',
styleUrls: ['./menu-example.css'],
})
export class MenuExample {
constructor(private menu: MenuController) { }
openFirst() {
this.menu.enable(true, 'first');
this.menu.open('first');
}
openEnd() {
this.menu.open('end');
}
openCustom() {
this.menu.enable(true, 'custom');
this.menu.open('custom');
}
}.my-custom-menu {
--width: 500px;
}<ion-app>
<ion-menu side="start" menu-id="first" content-id="main">
<ion-header>
<ion-toolbar color="primary">
<ion-title>Start Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-menu side="start" menu-id="custom" class="my-custom-menu" content-id="main">
<ion-header>
<ion-toolbar color="tertiary">
<ion-title>Custom Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-menu side="end" type="push" content-id="main">
<ion-header>
<ion-toolbar color="danger">
<ion-title>End Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<div class="ion-page" id="main">
<ion-header>
<ion-toolbar>
<ion-title>Menu - Basic</ion-title>
</ion-toolbar>
</ion-header>
<ion-content class="ion-padding">
<ion-button expand="block" onclick="openFirst()">Open Start Menu</ion-button>
<ion-button expand="block" onclick="openEnd()">Open End Menu</ion-button>
<ion-button expand="block" onclick="openCustom()">Open Custom Menu</ion-button>
</ion-content>
</div>
</ion-app><script type="module">
import { menuController } from '@ionic/core';
window.menuController = menuController;
</script>
<script>
function openFirst() {
menuController.enable(true, 'first');
menuController.open('first');
}
function openEnd() {
menuController.open('end');
}
function openCustom() {
menuController.enable(true, 'custom');
menuController.open('custom');
}
</script>.my-custom-menu {
--width: 500px;
}import React from 'react';
import { IonMenu, IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonItem, IonRouterOutlet } from '@ionic/react';
export const MenuExample: React.FC = () => (
<>
<IonMenu side="start" menuId="first">
<IonHeader>
<IonToolbar color="primary">
<IonTitle>Start Menu</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<IonList>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
</IonList>
</IonContent>
</IonMenu>
<IonMenu side="start" menuId="custom" className="my-custom-menu">
<IonHeader>
<IonToolbar color="tertiary">
<IonTitle>Custom Menu</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<IonList>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
</IonList>
</IonContent>
</IonMenu>
<IonMenu side="end" type="push">
<IonHeader>
<IonToolbar color="danger">
<IonTitle>End Menu</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<IonList>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
<IonItem>Menu Item</IonItem>
</IonList>
</IonContent>
</IonMenu>
<IonRouterOutlet></IonRouterOutlet>
</>
);import { Component, h } from '@stencil/core';
import { menuController } from '@ionic/core';
@Component({
tag: 'menu-example',
styleUrl: 'menu-example.css'
})
export class MenuExample {
openFirst() {
menuController.enable(true, 'first');
menuController.open('first');
}
openEnd() {
menuController.open('end');
}
openCustom() {
menuController.enable(true, 'custom');
menuController.open('custom');
}
render() {
return [
<ion-menu side="start" menuId="first" contentId="main">
<ion-header>
<ion-toolbar color="primary">
<ion-title>Start Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>,
<ion-menu side="start" menuId="custom" contentId="main" class="my-custom-menu">
<ion-header>
<ion-toolbar color="tertiary">
<ion-title>Custom Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>,
<ion-menu side="end" type="push" contentId="main">
<ion-header>
<ion-toolbar color="danger">
<ion-title>End Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>,
// A router outlet can be placed here instead
<ion-content id="main">
<ion-button expand="block" onClick={() => this.openFirst()}>Open Start Menu</ion-button>
<ion-button expand="block" onClick={() => this.openEnd()}>Open End Menu</ion-button>
<ion-button expand="block" onClick={() => this.openCustom()}>Open Custom Menu</ion-button>
</ion-content>
];
}
}.my-custom-menu {
--width: 500px;
}<template>
<ion-menu side="start" menu-id="first" content-id="main">
<ion-header>
<ion-toolbar color="primary">
<ion-title>Start Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-menu side="start" menu-id="custom" class="my-custom-menu" content-id="main">
<ion-header>
<ion-toolbar color="tertiary">
<ion-title>Custom Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-menu side="end" type="push" content-id="main">
<ion-header>
<ion-toolbar color="danger">
<ion-title>End Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
<ion-item>Menu Item</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-router-outlet id="main"></ion-router-outlet>
</template>
<style>
.my-custom-menu {
--width: 500px;
}
</style>
<script>
import {
IonContent,
IonHeader,
IonItem,
IonList,
IonMenu,
IonRouterOutlet,
IonTitle,
IonToolbar,
menuController
} from '@ionic/vue';
import { defineComponent } from 'vue';
export default defineComponent({
components: {
IonContent,
IonHeader,
IonItem,
IonList,
IonMenu,
IonRouterOutlet,
IonTitle,
IonToolbar
},
methods: {
openFirst() {
menuController.enable(true, 'first');
menuController.open('first');
},
openEnd() {
menuController.open('end');
},
openCustom() {
menuController.enable(true, 'custom');
menuController.open('custom');
}
}
});
</script>Properties
contentId | |
|---|---|
| Description | Các |
| Attribute | content-id |
| Type | string | undefined |
disabled | |
| Description | If |
| Attribute | disabled |
| Type | boolean |
| Default | false |
maxEdgeStart | |
| Description | Ngưỡng cạnh để kéo menu đang mở. Nếu kéo / vuốt xảy ra trên giá trị này, menu sẽ không được kích hoạt. |
| Attribute | max-edge-start |
| Type | number |
| Default | 50 |
menuId | |
| Description | Một id cho menu. |
| Attribute | menu-id |
| Type | string | undefined |
side | |
| Description | Menu nên được đặt ở phía nào của chế độ xem. |
| Attribute | side |
| Type | "end" | "start" |
| Default | 'start' |
swipeGesture | |
| Description | Nếu |
| Attribute | swipe-gesture |
| Type | boolean |
| Default | true |
type | |
| Description |
|
| Attribute | type |
| Type | string | undefined |
Events
| Name | Description |
|---|---|
ionDidClose | Phát ra khi đóng menu. |
ionDidOpen | Phát ra khi menu đang mở. |
ionWillClose | Phát ra khi sắp đóng menu. |
ionWillOpen | Phát ra khi menu sắp được mở. |
Methods
close | |
|---|---|
| Description | Đóng menu. Nếu menu đã được đóng hoặc không thể đóng được, menu sẽ quay trở lại |
| Signature | close(animated?: boolean) => Promise<boolean> |
isActive | |
| Description | Trả lại Một menu hoạt động khi nó có thể được mở hoặc đóng, có nghĩa là nó được bật và nó không phải là một phần của a |
| Signature | isActive() => Promise<boolean> |
isOpen | |
| Description | Trả lại |
| Signature | isOpen() => Promise<boolean> |
open | |
| Description | Mở menu. Nếu menu đã mở hoặc không thể mở được, menu sẽ quay trở lại |
| Signature | open(animated?: boolean) => Promise<boolean> |
setOpen | |
| Description | Mở hoặc đóng nút. Nếu thao tác không thể hoàn tất thành công, nó sẽ trả về |
| Signature | setOpen(shouldOpen: boolean, animated?: boolean) => Promise<boolean> |
toggle | |
| Description | Chuyển đổi menu. Nếu menu đã được mở, nó sẽ cố gắng đóng lại, nếu không nó sẽ cố gắng mở nó. Nếu thao tác không thể hoàn tất thành công, nó sẽ trả về |
| Signature | toggle(animated?: boolean) => Promise<boolean> |
CSS Shadow Parts
| Name | Description |
|---|---|
backdrop | The backdrop that appears over the main content when the menu is open. |
container | The container for the menu content. |
CSS Custom Properties
| Name | Description |
|---|---|
--background | Background of the menu |
--height | Height of the menu |
--max-height | Maximum height of the menu |
--max-width | Maximum width of the menu |
--min-height | Minimum height of the menu |
--min-width | Minimum width of the menu |
--width | Width of the menu |
Ion-menu-button
Nút Menu là thành phần tự động tạo biểu tượng và chức năng để mở menu trên một trang.
Properties
autoHide | |
|---|---|
| Description | Automatically hides the menu button when the corresponding menu is not active |
| Attribute | auto-hide |
| Type | boolean |
| Default | true |
color | |
| Description | The color to use from your application's color palette. Default options are: |
| Attribute | color |
| Type | string | undefined |
disabled | |
| Description | If |
| Attribute | disabled |
| Type | boolean |
| Default | false |
menu | |
| Description | Optional property that maps to a Menu's |
| Attribute | menu |
| Type | string | undefined |
mode | |
| Description | The mode determines which platform styles to use. |
| Attribute | mode |
| Type | "ios" | "md" |
type | |
| Description | The type of the button. |
| Attribute | type |
| Type | "button" | "reset" | "submit" |
| Default | 'button' |
CSS Shadow Parts
| Name | Description |
|---|---|
icon | The menu button icon (uses ion-icon). |
native | The native HTML button element that wraps all child elements. |
CSS Custom Properties
| Name | Description |
|---|---|
--background | Background of the menu button |
--background-focused | Background of the menu button when focused with the tab key |
--background-focused-opacity | Opacity of the menu button background when focused with the tab key |
--background-hover | Background of the menu button on hover |
--background-hover-opacity | Opacity of the background on hover |
--border-radius | Border radius of the menu button |
--color | Color of the menu button |
--color-focused | Color of the menu button when focused with the tab key |
--color-hover | Color of the menu button on hover |
--padding-bottom | Bottom padding of the button |
--padding-end | Right padding if direction is left-to-right, and left padding if direction is right-to-left of the button |
--padding-start | Left padding if direction is left-to-right, and right padding if direction is right-to-left of the button |
--padding-top | Top padding of the button |
ion-menu-toggle
Thành phần MenuToggle có thể được sử dụng để chuyển đổi mở hoặc đóng menu.
Theo mặc định, nó chỉ hiển thị khi menu đã chọn đang hoạt động. Một menu hoạt động khi nó có thể được mở / đóng. Nếu menu bị vô hiệu hóa hoặc nó được hiển thị dưới dạng ngăn chia nhỏ, menu sẽ được đánh dấu là không hoạt động và menu chuyển đổi ion tự ẩn.
Trong trường hợp muốn ion-menu-toggleluôn hiển thị, bạn autoHidecó thể đặt thuộc tính thành false.
Properties
autoHide | |
|---|---|
| Description | Tự động ẩn nội dung khi menu tương ứng không hoạt động. Theo mặc định, nó |
| Attribute | auto-hide |
| Type | boolean |
| Default | true |
menu | |
| Description | Thuộc tính tùy chọn ánh xạ tới chỗ dựa của Menu Nếu thuộc tính này không được sử dụng, |
| Attribute | menu |
| Type | string | undefined |
ion-split-pane
A split pane hữu ích khi tạo bố cục nhiều chế độ xem. Nó cho phép các phần tử giao diện người dùng, như menu, được hiển thị khi chiều rộng khung nhìn tăng lên.
Nếu chiều rộng màn hình của thiết bị dưới một kích thước nhất định, ngăn chia sẽ thu gọn và menu sẽ bị ẩn. Điều này lý tưởng để tạo một ứng dụng sẽ được phân phát trong trình duyệt và được triển khai thông qua cửa hàng ứng dụng cho điện thoại và máy tính bảng.
Setting Breakpoints
Theo mặc định, split pane mở rộng khi màn hình lớn hơn 992px. Để tùy chỉnh điều này, hãy chuyển một điểm ngắt trong thuộc whentính. Các điểm trong khi có thể chấp nhận một giá trị boolean, bất kỳ truy vấn phương tiện truyền thông hợp lệ, hoặc một trong các kích thước được xác định trước Ionic của.
<ion-split-pane when="md"></ion-split-pane>
<!-- can be any valid media query https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries -->
<ion-split-pane when="(min-width: 40px)"></ion-split-pane>| Size | Value | Description |
|---|---|---|
xs | (min-width: 0px) | Show the split-pane when the min-width is 0px (meaning, always) |
sm | (min-width: 576px) | Show the split-pane when the min-width is 576px |
md | (min-width: 768px) | Show the split-pane when the min-width is 768px |
lg | (min-width: 992px) | Show the split-pane when the min-width is 992px (default break point) |
xl | (min-width: 1200px) | Show the split-pane when the min-width is 1200px |
Usage
<ion-split-pane contentId="main">
<!-- the side menu -->
<ion-menu contentId="main">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
</ion-menu>
<!-- the main content -->
<ion-router-outlet id="main"></ion-router-outlet>
</ion-split-pane><ion-split-pane content-id="main">
<!-- the side menu -->
<ion-menu content-id="main">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
</ion-menu>
<!-- the main content -->
<ion-content id="main">
<h1>Hello</h1>
</ion-content>
</ion-split-pane>import React from 'react';
import {
IonSplitPane,
IonMenu,
IonHeader,
IonToolbar,
IonTitle,
IonRouterOutlet,
IonContent,
IonPage
} from '@ionic/react';
export const SplitPlaneExample: React.SFC<{}> = () => (
<IonContent>
<IonSplitPane contentId="main">
{/*-- the side menu --*/}
<IonMenu contentId="main">
<IonHeader>
<IonToolbar>
<IonTitle>Menu</IonTitle>
</IonToolbar>
</IonHeader>
</IonMenu>
{/*-- the main content --*/}
<IonPage id="main"/>
</IonSplitPane>
</IonContent>
);import { Component, h } from '@stencil/core';
@Component({
tag: 'split-pane-example',
styleUrl: 'split-pane-example.css'
})
export class SplitPaneExample {
render() {
return [
<ion-split-pane content-id="main">
{/* the side menu */}
<ion-menu content-id="main">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
</ion-menu>
{/* the main content */}
<ion-router-outlet id="main"></ion-router-outlet>
</ion-split-pane>
];
}
}<template>
<ion-split-pane content-id="main">
<!-- the side menu -->
<ion-menu content-id="main">
<ion-header>
<ion-toolbar>
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
</ion-menu>
<!-- the main content -->
<ion-router-outlet id="main"></ion-router-outlet>
</ion-split-pane>
</template>
<script>
import {
IonHeader,
IonMenu,
IonRouterOutlet,
IonSplitPane,
IonTitle,
IonToolbar
} from '@ionic/vue';
import { defineComponent } from 'vue';
export default defineComponent({
components: {
IonHeader,
IonMenu,
IonRouterOutlet,
IonSplitPane,
IonTitle,
IonToolbar
}
});
</script>Properties
contentId | |
|---|---|
| Description | The |
| Attribute | content-id |
| Type | string | undefined |
disabled | |
| Description | If |
| Attribute | disabled |
| Type | boolean |
| Default | false |
when | |
| Description | Khi split-pane được hiển thị. Có thể là một biểu thức truy vấn phương tiện CSS hoặc một biểu thức tắt. Cũng có thể là một biểu thức boolean. |
| Attribute | when |
| Type | boolean | string |
| Default | QUERY['lg'] |
Events
| Name | Description |
|---|---|
ionSplitPaneVisible | Biểu thức được gọi khi chế độ split-pane đã thay đổi |
CSS Custom Properties
| Name | Description |
|---|---|
--border | Border between panes(Đường viền giữa các ô) |
--side-max-width | Maximum width of the side pane. Does not apply when split pane is collapsed.(Chiều rộng tối đa của ngăn bên. Không áp dụng khi ngăn chia bị thu gọn.) |
--side-min-width | Minimum width of the side pane. Does not apply when split pane is collapsed.(Chiều rộng tối thiểu của ngăn bên. Không áp dụng khi ngăn chia bị thu gọn.) |
--side-width | Width of the side pane. Does not apply when split pane is collapsed.(Chiều rộng của ngăn bên. Không áp dụng khi ngăn chia bị thu gọn.) |

0 Nhận xét