應用程式佈局

我們應該為應用程式執行的第一件事是建立包含應用程式架構的 index.html 檔案。Framework7 React 旨在與 webpack 等套件管理員搭配使用,因此 index.html 的樣式和腳本應該會自動注入/產生。

<!DOCTYPE html>
<html>
  <head>
    <!-- Required meta tags-->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, viewport-fit=cover">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <!-- Color theme for statusbar (Android only) -->
    <meta name="theme-color" content="#2196f3">
    <!-- Your app title -->
    <title>My App</title>
    <!-- Framework7 styles -->
    <link rel="stylesheet" href="path/to/framework7-bundle.min.css">
  </head>
  <body>
    <!-- App Root Element -->
    <div id="app"></div>

    <!-- Scripts will be auto injected -->
  </body>
</html>

<div id="app"></div> 是您主要的應用程式架構所在位置。您可以將其內容作為元件掛載,或者(僅舉例來說)我們可以在這個 div 內部開始撰寫應用程式架構

基本配置

讓我們看看最基本的應用程式元件配置

// App.jsx
import { App, View, Page, Navbar, Toolbar, Link } from 'framework7-react';

export default () => (
  // Main Framework7 App component where we pass Framework7 params
  <App theme="auto" name="My App">

    {/* Your main view, should have "main" prop */}
    <View main>
      {/*  Initial Page */}
      <Page>
        {/* Top Navbar */}
        <Navbar title="Awesome App"></Navbar>
        {/* Toolbar */}
        <Toolbar bottom>
          <Link>Link 1</Link>
          <Link>Link 2</Link>
        </Toolbar>
        {/* Page Content */}
        <p>Page content goes here</p>
        <Link href="/about/">About App</Link>
      </Page>
    </View>
  </App>
)

進階配置

現在,讓我們看看更進階的配置,我們將在其中新增包含檢視和彈出視窗的側邊面板

// App.jsx

import { App, NavRight, Panel, View, Page, Navbar, Block, Button, Popup, Link } from 'framework7-react';

export default () => (
  /* Main Framework7 App component where we pass Framework7 params */
  <App theme="auto" name="My App">

    {/* Left Panel with "cover" effect */}
    <Panel left cover>
      <View>
        <Page>
          <Navbar title="Left Panel"></Navbar>
          <Block>
            <p>Here comes the left panel text</p>
          </Block>
        </Page>
      </View>
    </Panel>

    {/* Right Panel with "reveal" effect */}
    <Panel right reveal>
      <View>
        <Page>
          <Navbar title="Right Panel"></Navbar>
          <Block>
            <p>Here comes the right panel text</p>
          </Block>
        </Page>
      </View>
    </Panel>

    {/*  Main view */}
    <View main>
      <Page>
        <Navbar title="Awesome App"></Navbar>
        {/* Page content */}
        <Block>
          <p>Here comes main view page text</p>
        </Block>
        {/* Buttons to open panels */}
        <Block className="grid grid-cols-2 grid-gap">
          <Button panelOpen="left">Left Panel</Button>
          <Button panelOpen="right">Right Panel</Button>
        </Block>
        {/* Button to open popup */}
        <Button popupOpen="#my-popup">Open Popup</Button>
      </Page>
    </View>

    {/* Popup. All modals should be outside of Views */}
    <Popup id="my-popup">
      <View>
        <Page>
          <Navbar title="Popup">
            {/* Link to close popup */}
            <NavRight>
              <Link popupClose>Close</Link>
            </NavRight>
          </Navbar>
          <Block>
            <p>Here comes popup text</p>
          </Block>
        </Page>
      </View>
    </Popup>
  </App>
)

您可以在適當的章節中閱讀更多關於檢視、導覽列、工具列、頁面、面板和其他元件的資訊。

初始化應用程式

現在我們有了基本範本,我們需要在(例如)my-app.js初始化我們的應用程式