Introducing Vue Native

June 12, 2018 0 Comments

Introducing Vue Native



We at GeekyAnts are very excited to share one of our side projects which we have been working on for a while, Vue Native!

Though the sentiment in the JavaScript community about Vue has been mixed, we couldn’t stop ourselves to try Vue for native mobile app development.

Here is a simple Vue Native code snippet that renders some text on the mobile screen.

As a web developer, we always loved the simplicity of writing HTML code and then styling it with CSS. Vue provides us with a similar experience with .vue files.

As a team which is very active in the React Native community with contributions like NativeBase, we are never biased about our opinion to try new frameworks and languages. Vue is one of them and it suits the use-cases to build most of our apps.

The support for templating, styling, state-management with Vuex and router makes Vue the perfect choice.

With Vue Native, we are bringing the same experience to native mobile app development.

With a quick search on the web, we came across react-vue by SmallComfort. react-vue transpiles Vue files to React & React Native Components. Kudos to the author of react-vue which solves most of the problem. Vue Native is a fork of the same.

React Native is a direct dependency of Vue Native. Once you initialize a new app using vue-native-cli, the entry script is App.vue.

Just like a .js file, you can compose a .vue files with many .vue files. All these .vue files are actually converted to React Native component files with .js. You can read more about it here.

Vue Native is also capable of achieving two-way data binding with the help of v-model directive as shown in the code snippet below.

To write loops, we can use Vue’s v-for directive. The v-for directive is similar to JavaScript’s map operator.

In order to use Vue Native, you will first need to install React Native on your system. Follow the steps given here to install React Native.

Next, we can install the Vue Native CLI on your system using NPM.

$ npm install -g vue-native-cli

With that, all you need to do now is initialize a new Vue-Native project directory in your system.

$ vue-native init <projectName>
$ cd <projectName>

You can now run this Vue Native app on an iOS or Android Simulator using the npm run command.

Directives are special attributes that are found in Vue. These are attributes that come with the v- prefix. Here are a few of these directives and where they can be used in Vue.

The v-if and v-else directives are used in Vue to write conditional code blocks.

Running this code on your system will give you this output:

The v-for directive is similar to JavaScript’s map operator.

Running this code on your system will give you this output:

v-model directive creates a two-way data binding on a form input element or a component. Internally it attaches value and onChangeText handler to TextInput of React Native.

The above code snippet creates a two-way data binding on textContent, so when the types something in the text-input, it will be stored in textContent, which will then be displayed right below the text-input field.

Vue Native uses vue-router for implementing navigation in your mobile apps. Let’s take a look at how Drawer Navigation can be implemented using Vue Native.

It’s a simple wrapper around React Navigation of React Native.

  • Sometimes for a component, you might have to create a function that returns JSX code.
    For example: renderItem in FlatList must return JSX.
  • The error reporting is on the React Native level and it doesn’t map to the Vue Native code yet. We are working towards it.

We have rebuilt the complete NativeBase KitchenSink app in Vue Native. You can use it in production but with the known issues and limitations above.

Tag cloud