Ionic 4 Tutorial with Vue

Ionic 4 Tutorial with Vue

In this post we will give you information about Ionic 4 Tutorial with Vue. Hear we will give you detail about Ionic 4 Tutorial with VueAnd how to use it also give you demo for it if it is necessary.

Ionic 4 is the latest version of Ionic that utilizes web components thanks to Stencil

Ionic 4 allows you to use any JavaScript/TypeScript front end library or framework such as Angular, AngularJS, Vue or React etc. to build mobile applications so you are not forced to TypeScript and Angular like the previous versions i.e 3.x.x or before.


In this Ionic 4 tutorial you will learn

  • how to install the Vue CLI
  • how to use the Vue CLI to generate a new Vue project
  • how to integrate Ionic 4 components with your Vue application

Generating the Vue Application

First of all make sure you have Node and NPM installed then start by installing the Vue CLI

$ npm install vue-cli -g

This will install the Vue CLI globally. If the installation fails for permission reasons you might want to add sudo to your command.

Now you can create a new Vue.js project based on the Webpack template so just run the following command

$ vue init webpack ionic4-vue

The Vue CLI will ask you for a bunch of information and whether you want to use some components like the Vue Router or not. Answer those questions then wait for your project to be generated and for the dependencies to be installed.

Next navigate inside your project root folder and run

$ npm run dev

This will start the Webpack development server on port 8080. You can navigate with your web browser to http://localhost:8080 to see your Vue application up and running

Adding Ionic 4

To add Ionic 4 components to your Vue application you will have to use the core Ionic JS file. That’s the only way for now until Ionic 4 final will be released.

So go ahead and open the index.html which lives at the root folder of your Vue application and then add the following <script src=''></script> tag to include the Ionic 4 core file that contains the UI components you usually use with Ionic.

<!DOCTYPE html><html><head><metacharset="utf-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>ionic4-vue</title><script src=''></script></head><body><divid="app"></div><!-- built files will be auto injected --></body></html>

Next open src/components/HelloWorld.vue component then add the following content:

<template><ion-app><ion-pageclass="show-page"><ion-header><ion-toolbar><ion-title>Ionic 4 + Vue Application </ion-title></ion-toolbar></ion-header><ion-contentclass="content"padding><ion-list><ion-itemv-for="item of items"v-bind:key=""><ion-labelfull></ion-label></ion-item></ion-list></ion-content></ion-page></ion-app></template>

This makes use of <ion-list> to display a set of items

You can also use any other Ionic 4 component so feel free to experiment with your demo application to understand how Ionic components can be used in Vue.

If your run your application in a real mobile device you will notice a problem in scaling. You can fix the scaling issue on mobile all you need to do is using a <meta> tag that sets the viewport

Add these meta tags from an Ionic application:

<metaname="viewport"content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"><metaname="format-detection"content="telephone=no"><metaname="msapplication-tap-highlight"content="no">

Adding Routing/Navigation

Next you will use the Vue Router to navigate between different pages in your application since the Ionic Navigation Controller is not available in Vue (it’s an Angular component)

So add an Ionic 4 button in HelloWorld.vue component and bind its click handler to a goToPage2() method

<ion-button@click="goToPage2"full>Go To Page II</ion-button>

Next in the same file add the following code


The goToPage2() method uses the push() method of the Vue Router to navigate to page 2 (similar concepts to Ionic/Angular NavController)

Now you need to create the Page 2 component

In src/components create the file Page2.vue then add the following content

<template><ion-app><ion-pageclass="show-page"><ion-header><ion-toolbar><ion-title>Ionic 4 + Vue Application </ion-title></ion-toolbar></ion-header><ion-contentclass="content"padding>        This is page 2      </ion-content></ion-page></ion-app></template><script>exportdefault{name:'App',data(){return{}},methods:{}}</script>

Next you need to create a route for this component. Open src/router/index.js then update it to reflect the changes

importVuefrom'vue'importRouterfrom'vue-router'importHelloWorldfrom'@/components/HelloWorld'importPage2from'@/components/Page2'Vue.use(Router)exportdefaultnewRouter({routes:[{path:'/',name:'HelloWorld',component:HelloWorld},{path:'/page2',name:'Page 2',component:Page2}]})

We import the Page2 component we created before then we add a new route to setup navigation.

Also head back to Page2.vue and add an Ionic 4 button to navigate back to the HelloWorld page

<ion-button@click="goToHome"full>Go Home</ion-button>

Next add the goToHome method to the array of methods


When using Ionic with Angular you have NavController which relives you from explicitly define routes for your application but when using Ionic with Vue you don’t have any Vue helper classes to achieve the same thing so you need to define your routes manually.

Integrating Vue with Cordova

First let’s start by installing Cordova globally if you don’t already have it installed

Open your terminal and run the following command

npm install -g cordova

Next you need to create a Cordova project by running the following command:

cordova create ionic-vue-cordova

Next navigate inside your project folder then copy the built files of your previously created Vue application inside the www of your Cordova project

Also make sure to clear the www from any files before your copy Vue files and add the following line to index.html

Add the cordova.js file to index.html:

<script type="text/javascript" src="cordova.js"></script>

A better way to do this is by placing your Vue project inside the Cordova project then setup Vue Webpack files to directly generate the built files inside the Cordova www folder

Simply open config/index.js then change the target build folder to www:


Also the assetsPublicPath is changed from /. to ./ this will allow the files to be loaded with Cordova.

Building for iOS and Android

Building your app for Android or iOS is similar on how you usually do that with Ionic (since it also uses Cordova behind the curtain).

So you first need to add a target platform

cordova platform add ios --savecordova platform add android --save

Next you need to build your Vue app then copy the files inside the www folder

npm run build

If you have configured the Vue application to output files inside the www folder directly then you don’t need to manually copy them.

Next use the following commands to run your app in a real device

cordova run ios --devicecordova run android --device


In this Ionic 4 tutorial we’ve seen how to build a simple mobile application with Vue, Ionic 4 and Cordova.

Hope this code and post will helped you for implement Ionic 4 Tutorial with Vue. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US