Framework7 - 環境



本章將討論如何安裝和設定 Framework7。

您可以透過兩種方式下載 Framework7:

Framework7 Github 倉庫 下載

您可以使用 Bower 安裝 Framework7,如下所示:

bower install framework7

成功安裝 Framework7 後,您需要按照以下步驟在您的應用程式中使用 Framework7:

步驟 1 - 您需要安裝 gulp-cli 來構建 Framework7 的開發和發行版本,使用以下命令:

npm install gulp-cli

cli 代表 Gulp 的命令列工具。

步驟 2 - 必須使用以下命令全域性安裝 Gulp。

npm install --global gulp

步驟 3 - 接下來,安裝 NodeJS 包管理器,它安裝 node 程式,使指定和連結依賴項更容易。使用以下命令安裝 npm。

npm install

步驟 4 - 可以使用以下命令構建 Framework7 的開發版本。

npm build

步驟 5 - 構建 Framework7 的開發版本後,使用以下命令從 dist/ 資料夾開始構建應用程式。

npm dist

步驟 6 - 將您的應用程式資料夾儲存在伺服器中,並執行以下命令以在應用程式的頁面之間導航。

gulp server

從 CDN 下載 Framework7 庫

CDN 或內容分發網路是一個伺服器網路,旨在向用戶提供檔案。如果您在網頁中使用 CDN 連結,它會將託管檔案的責任從您自己的伺服器轉移到一系列外部伺服器。 這也提供了一個優勢,如果您的網頁訪問者已經從同一個 CDN 下載了 Framework7 的副本,則無需重新下載。您可以將以下 CDN 檔案包含到 HTML 文件中。

以下 CDN 用於iOS 應用程式佈局

<link rel = "stylesheet" 
   href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.min.css" />

它用於將 Framework7 iOS CSS 庫包含到您的應用程式中。

<link rel = "stylesheet" 
   href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.colors.min.css" />

它用於將 Framework7 iOS 相關的顏色樣式包含到您的應用程式中。

以下 CDN 用於Android/Material 應用程式佈局

<script src = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/js/framework7.min.js"></script>

它用於將 Framework7 JS 庫包含到您的應用程式中。

<script src = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.material.min.css"></script>

它用於將 Framework7 Material 樣式包含到您的應用程式中。

在本教程中,我們使用庫的 CDN 版本。我們使用 AMPPS(AMPPS 是 Apache、MySQL、MongoDB、PHP、Perl 和 Python 的 WAMP、MAMP 和 LAMP 整合環境)伺服器來執行所有示例。

示例

以下示例演示了在 Framework7 中使用簡單應用程式的方法,當您單擊導航欄時,它將顯示帶有自定義訊息的警告框。

<!DOCTYPE html>
<html>
   
   <head>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1, 
         maximum-scale = 1, minimum-scale = 1, user-scalable = no, minimal-ui" />
      <meta name = "apple-mobile-web-app-capable" content = "yes" />
      <meta name = "apple-mobile-web-app-status-bar-style" content = "black" />
      <title>My App</title>
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.min.css" />
      <link rel = "stylesheet" 
         href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.colors.min.css" />
   </head>
   
   <body>
      //you can control the background color of the Status bar
      <div class = "statusbar-overlay"></div>
      <div class = "panel-overlay"></div>
      
      <div class = "panel panel-right panel-reveal">
         <div class = "content-block">
            <p>Contents goes here...</p>
         </div>
      </div>
      
      <div class = "views">
         <div class = "view view-main">
            <div class = "navbar">
               <div class = "navbar-inner">
                  <div class = "center sliding">My App</div>
                  <div class = "right">
                     <a href = "#" class = "link icon-only open-panel">
                        <i class = "icon icon-bars"></i>
                     </a>
                  </div>
               </div>
            </div>
            
            <div class = "pages navbar-through toolbar-through">
               <div data-page = "index" class = "page">
                  <div class = "page-content">
                     <p>This is simple application...</p>
                     <div class = "list-block">
                        <ul>
                           <li>
                              <a href = "envirmnt_about.html" class = "">
                                 <div class = "item-content">
                                    <div class = "item-inner">
                                       <div class = "item-title">Blog</div>
                                    </div>
                                 </div>
                              </a>
                           </li>
                        </ul>
                     </div>
                  </div>
               </div>
            </div>
            
            <div class = "toolbar">
               <div class = "toolbar-inner">
                  <a href = "#" class = "link">First Link</a>
                  <a href = "#" class = "link">Second Link</a>
               </div>
            </div>
         </div>
      </div>
      
      <script type = "text/javascript" 
         src = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/js/framework7.min.js"></script>
      
      <script>
         // here initialize the app
         var myApp = new Framework7();

         // If your using custom DOM library, then save it to $$ variable
         var $$ = Dom7;

         // Add the view
         var mainView = myApp.addView('.view-main', {
            
            // enable the dynamic navbar for this view:
            dynamicNavbar: true
         });

         //use the 'pageInit' event handler for all pages
         $$(document).on('pageInit', function (e) {
         
            //get page data from event data
            var page = e.detail.page;

            if (page.name === 'blog') {
            
               // you will get below message in alert box when page with data-page attribute is equal to "about"
               myApp.alert('Here its your About page');
            }
         })
      </script>
   </body>

</html>

接下來,建立另一個 HTML 頁面,即envirmnt_about.html,如下所示:

envirmnt_about.html

<div class = "navbar">
   <div class = "navbar-inner">
      <div class = "left">
         <a href = "#" class = "back link">
            <i class = "icon icon-back"></i>
            <span>Back</span>
         </a>
      </div>
      
      <div class = "center sliding">My Blog</div>
      <div class = "right">
         <a href = "#" class = "link icon-only open-panel">
            <i class = "icon icon-bars"></i>
         </a>
      </div>
   </div>
</div>

<div class = "pages">
   <div data-page = "blog" class = "page">
      <div class = "page-content">
         <div class = "content-block">
            <h2>My Blog</h2>
            <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
         </div>
      </div>
   </div>
</div>

輸出

讓我們執行以下步驟來檢視上面給出的程式碼是如何工作的:

  • 將上述 HTML 程式碼儲存為framework7_environment.html檔案到您的伺服器根資料夾。

  • 開啟此 HTML 檔案,網址為 https:///framework7_environment.html,輸出將顯示如下。

  • 當您單擊導航欄時,它將顯示帶有自定義訊息的警告框。

廣告