Goglides Dev 🌱

Cover image for Getting Started with Mobile Apps Using NativeScript & Vue.js
Ethan Patrick
Ethan Patrick

Posted on

Getting Started with Mobile Apps Using NativeScript & Vue.js

To get started building mobile apps with NativeScript and Vue.js, you will need to set up your environment, install the necessary command-line tools, and create a new project using a template. NativeScript uses a custom renderer to translate Vue components into native UI elements for iOS and Android, allowing you to use your existing Vue knowledge to create truly native applications.

If you are expanding your team, you may be looking to hire Vue.js developers to help with your project. The knowledge you gain from this guide will also be helpful in assessing potential candidates and ensuring a successful collaboration.

Prerequisites

Before you begin, ensure your system has the following installed:

  • Node.js: The latest version is recommended. You can verify your installation by running node -v in your terminal.
  • iOS and Android SDKs: To build and run apps locally on emulators or physical devices, you will need to configure your environment for mobile development. The ns doctor command will help you install the necessary dependencies for your operating system.

Step 1: Install NativeScript and Vue CLI

You will need the NativeScript Command-Line Interface (CLI) to manage your projects and the Vue CLI to scaffold them.
Open your terminal or command prompt.
Install the NativeScript CLI globally by running:

npm install -g nativescript
Enter fullscreen mode Exit fullscreen mode

Install the Vue CLI globally by running:

npm install -g @vue/cli @vue/cli-init
Enter fullscreen mode Exit fullscreen mode

After installation, run ns to confirm the NativeScript CLI is working correctly.

Step 2: Set up your development environment

The ns doctor command is the most reliable way to check for and fix any issues with your setup, including installing or configuring the iOS and Android SDKs.
Run the following command in your terminal:

ns doctor
Enter fullscreen mode Exit fullscreen mode

Follow the instructions provided by the tool to resolve any reported issues. For example, it will guide you through setting up Xcode for iOS or Android Studio for Android.

Step 3: Create a new NativeScript-Vue project

You can create a new project using the ns create command with the NativeScript-Vue template.
Run the following command, replacing myAwesomeApp with your desired project name:

ns create myAwesomeApp --template @nativescript-vue/template-blank
Enter fullscreen mode Exit fullscreen mode

Change into your new project directory:

cd myAwesomeApp 
Enter fullscreen mode Exit fullscreen mode

Step 4: Run your app

Now you can launch your newly created app on a connected device or emulator.
To run on iOS:

ns run ios
Enter fullscreen mode Exit fullscreen mode

To run on Android:

ns run android
Enter fullscreen mode Exit fullscreen mode

To preview the app instantly on your physical device without a full local setup, use the NativeScript Preview app.
Install the NativeScript Preview app from the iOS App Store or Google Play Store.
Run the following command from your project directory:

ns preview
Enter fullscreen mode Exit fullscreen mode

Scan the QR code that appears in your terminal with the NativeScript Preview app.

Step 5: Start building your app

With your project running, you can begin exploring the project structure and building out your UI.

  • UI components: Unlike web development, you will use NativeScript UI components instead of standard HTML tags. For example, a is used for text, and a is used for a container, much like a .
  • Single-File Components: NativeScript-Vue fully supports Vue's single-file component structure (.vue files), allowing you to keep your template, logic, and styling together.
  • Example component:

<template>
  <Page>
    <StackLayout>
      <Label text="Hello, NativeScript-Vue!" class="title" />
    </StackLayout>
  </Page>
</template>

<script>
export default {
  // Your Vue.js logic goes here
};
</script>

<style>
.title {
  font-size: 24;
  text-align: center;
  margin-top: 20;
}
</style>

Conclusion

Getting started with NativeScript and Vue.js offers a direct path to cross-platform mobile development using familiar web technologies. By combining Vue's approachable reactivity with NativeScript's ability to render truly native UI components, developers can create high-performance apps for iOS and Android from a single codebase.

This flexibility contrasts with the more prescriptive, all-in-one approach of other frameworks. While the Angular vs Vue debate offers different developer experiences, Angular being suited for large enterprise applications with a steeper learning curve, and Vue for its lightweight, flexible nature, the NativeScript-Vue combination proves to be a robust, efficient, and intuitive choice for those wanting to build native mobile apps quickly.

Top comments (0)