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 Initialization 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:

  1. <!-- index.html -->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <!-- ... metas and styles ... -->
  6. <link rel="stylesheet" href="path/to/framework7.bundle.min.css">
  7. </head>
  8. <body>
  9. <!-- App Root Element -->
  10. <div id="app">
  11. <!-- Main Framework7 App component where we pass Framework7 params -->
  12. <f7-app :params="$root.f7params">
  13. <f7-view main>
  14. <!-- Initial Page -->
  15. <f7-page>
  16. <f7-navbar title="Awesome App"></f7-navbar>
  17. <f7-toolbar bottom>
  18. <f7-link>Link 1</f7-link>
  19. <f7-link>Link 2</f7-link>
  20. </f7-toolbar>
  21. <p>Page content goes here</p>
  22. <f7-link href="/about/">About App</f7-link>
  23. </f7-page>
  24. </f7-view>
  25. </f7-app>
  26. </div>
  27. <script type="text/javascript" src="path/to/vue.min.js"></script>
  28. <script type="text/javascript" src="path/to/framework7.bundle.min.js"></script>
  29. <script type="text/javascript" src="path/to/framework7-vue.bundle.min.js"></script>
  30. <script type="text/javascript" src="path/to/my-app.js"></script>
  31. </body>
  32. </html>
  1. /* my-app.js */
  2. // First of all, we need to initialize/enable Framework7 Vue plugin:
  3. // We need to pass Framework7Vue plugin to Framework7's .use() method
  4. Framework7.use(Framework7Vue);
  5. // Init Vue App
  6. new Vue({
  7. // App Root Element
  8. el: '#app',
  9. // App root data
  10. data() {
  11. return {
  12. // Framework7 parameters that we pass to <f7-app> component
  13. f7params: {
  14. // Array with app routes
  15. routes: [...]
  16. // App Name
  17. name: 'My App',
  18. // App id
  19. id: 'com.myapp.test',
  20. // ...
  21. }
  22. };
  23. },
  24. // App root methods
  25. methods: {
  26. // ....
  27. }
  28. })

ES Modules

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

  1. <!-- index.html -->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <!-- ... metas and styles ... -->
  6. <link rel="stylesheet" href="path/to/framework7.bundle.min.css">
  7. </head>
  8. <body>
  9. <!-- App Root Element -->
  10. <div id="app"></div>
  11. <script type="text/javascript" src="path/to/my-app.js"></script>
  12. </body>
  13. </html>
  1. /* my-app.js */
  2. // Import Vue
  3. import Vue from 'vue'
  4. // Import F7 Bundle
  5. import Framework7 from 'framework7/framework7-lite.esm.bundle.js'
  6. // Import F7-Vue Plugin Bundle (with all F7 components registered)
  7. import Framework7Vue from 'framework7-vue/framework7-vue.esm.bundle.js'
  8. // Init F7-Vue Plugin
  9. Framework7.use(Framework7Vue);
  10. // Import Main App component
  11. import App from './app.vue';
  12. // Init App
  13. new Vue({
  14. el: '#app',
  15. render: (h) => h(App),
  16. // ...
  17. });
  1. <!-- app.vue -->
  2. <template>
  3. <!-- Main Framework7 App component where we pass Framework7 params -->
  4. <f7-app :params="f7params">
  5. <!-- initial page is specified in routes.js -->
  6. <f7-view main url="/"></f7-view>
  7. </f7-app>
  8. </template>
  9. <script>
  10. import routes from './routes.js';
  11. export default {
  12. data() {
  13. return {
  14. // Framework7 parameters that we pass to <f7-app> component
  15. f7params: {
  16. // Array with app routes
  17. routes,
  18. // App Name
  19. name: 'My App',
  20. // App id
  21. id: 'com.myapp.test',
  22. // ...
  23. }
  24. }
  25. }
  26. }
  27. </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.

← App Layout

Vue Component Extensions →