Initialize App

After we have our app layout now we need to mount Vue components and initialize the app. You can read about all possible Framework7 initialization parameters in appropriate Framework7 App Parameters section.

Plain Initiliazation Structure

Let's look at the simple plain app structure, where we don't use any bundlers in our app, just a plain html + js files. Full layout again, but with script:

<!-- index.html -->

<!DOCTYPE html>
<html>
  <head>
    <!-- ... metas and styles ... -->
    <link rel="stylesheet" href="path/to/framework7.bundle.min.css">
  </head>
  <body>
    <!-- App Root Element -->
    <div id="app">
      <!-- Main Framework7 App component where we pass Framework7 params -->
      <f7-app :params="$root.f7params">

        <f7-view main>
          <!-- Initial Page -->
          <f7-page>
            <f7-navbar title="Awesome App"></f7-navbar>
            <f7-toolbar bottom>
              <f7-link>Link 1</f7-link>
              <f7-link>Link 2</f7-link>
            </f7-toolbar>
            <p>Page content goes here</p>
            <f7-link href="/about/">About App</f7-link>
          </f7-page>
        </f7-view>
      </f7-app>
    </div>
    <script type="text/javascript" src="path/to/vue.min.js"></script>
    <script type="text/javascript" src="path/to/framework7.bundle.min.js"></script>
    <script type="text/javascript" src="path/to/framework7-vue.bundle.min.js"></script>
    <script type="text/javascript" src="path/to/my-app.js"></script>
  </body>
</html>
/* my-app.js */

// First of all, we need to initialize/enable Framework7 Vue plugin:
// We need to pass Framework7Vue plugin to Framework7's .use() method
Framework7.use(Framework7Vue);

// Init Vue App
new Vue({
  // App Root Element
  el: '#app',

  // App root data
  data() {
    return {
      // Framework7 parameters that we pass to <f7-app> component
      f7params: {
        // Array with app routes
        routes: [...]
        // App Name
        name: 'My App',
        // App id
        id: 'com.myapp.test',
        // ...
      }
    };
  },
  // App root methods
  methods: {
    // ....
  }
})

ES Modules

If you use Webpack, Rollup or another bundler with ES-next modules support, we may have the following structure:

<!-- index.html -->

<!DOCTYPE html>
<html>
  <head>
    <!-- ... metas and styles ... -->
    <link rel="stylesheet" href="path/to/framework7.bundle.min.css">
  </head>
  <body>
    <!-- App Root Element -->
    <div id="app"></div>
    <script type="text/javascript" src="path/to/my-app.js"></script>
  </body>
</html>
/* my-app.js */

// Import Vue
import Vue from 'vue'

// Import F7 Bundle
import Framework7 from 'framework7/framework7-lite.esm.bundle.js'

// Import F7-Vue Plugin Bundle (with all F7 components registered)
import Framework7Vue from 'framework7-vue/framework7-vue.esm.bundle.js'

// Init F7-Vue Plugin
Framework7.use(Framework7Vue);

// Import Main App component
import App from './app.vue';

// Init App
new Vue({
  el: '#app',
  render: (h) => h(App),
  // ...
});
<!-- app.vue -->

<template>
  <!-- Main Framework7 App component where we pass Framework7 params -->
  <f7-app :params="f7params">
    <!-- initial page is specified in routes.js -->
    <f7-view main url="/"></f7-view>
  </f7-app>
</template>
<script>
  import routes from './routes.js';

  export default {
    data() {
      return {
        // Framework7 parameters that we pass to <f7-app> component
        f7params: {
          // Array with app routes
          routes,
          // App Name
          name: 'My App',
          // App id
          id: 'com.myapp.test',
          // ...
        }
      }
    }
  }
</script>

In the examples above:

  • we pass Framework7 parameters to the f7-app main Framework7 app component in its params property;
  • element passed in Vue's el parameter will be used as Framework7 root element

We also must specify array with routes (if we have navigation between pages in the app). Check out information about Vue Component Extensions, router and routes in the Navigation Router section.