Categories
NativeScript Vue

NativeScript Vue — Date Picker, Frame, HtmlView, and Images

Spread the love

Vue is an easy to use framework for building front end apps.

NativeScript is a mobile app framework that lets us build native mobile apps with popular front end frameworks.

In this article, we’ll look at how to build an app with NativeScript Vue.

DatePicker

NativeScript Vue comes with a date picker component.

To use it, we add:

<template>
  <Page>
    <ActionBar title="NativeScript App"></ActionBar>
    <FlexboxLayout flexDirection="column">
      <DatePicker v-model="selectedDate" />
      <Label :text="selectedDate" style="text-align: center" />
    </FlexboxLayout>
  </Page>
</template>

<script >
export default {
  data() {
    return {
      selectedDate: undefined,
    };
  },
};
</script>

We add the DatePicker with the v-model directive to bind the selected value to the selectedDate reactive property.

Also, we can restrict the date range that we can choose with the minDate and maxDate props.

They’ll set the min and max dates that we can choose.

date get or set the complete date.

And day , month , and year gets or sets the day, month, and year respectively.

Frame

The Frame component is the root element for our app.

Every app needs at least one Frame .

We can have also more than one Frame.

For example, in main.js , we have:

import Vue from 'nativescript-vue'
import App from './components/App'
import VueDevtools from 'nativescript-vue-devtools'

if(TNS_ENV !== 'production') {
  Vue.use(VueDevtools)
}

// Prints Vue logs when --env.production is *NOT* set while building
Vue.config.silent = (TNS_ENV === 'production')

new Vue({

  render: h => h('frame', [h(App)])
}).$start()

to render the frame.

HtmlView

We can add the HtmlView component to show static HTML content in our NativeScript Vue app.

For example, we can write:

<template>
  <Page>
    <ActionBar title="NativeScript App"></ActionBar>
    <FlexboxLayout flexDirection="column">
      <HtmlView html="<div><h1>HtmlView</h1></div>" />
    </FlexboxLayout>
  </Page>
</template>

<script >
export default {};
</script>

to add the HtmlView to display the raw HTML in the html prop.

Image

The Image component lets us show images.

For example, we can write:

<template>
  <Page>
    <ActionBar title="NativeScript App"></ActionBar>
    <FlexboxLayout flexDirection="column">
      <Image
        src="https://i.picsum.photos/id/23/200/200.jpg?hmac=IMR2f77CBqpauCb5W6kGzhwbKatX_r9IvgWj6n7FQ7c"
        stretch="none"
      />
    </FlexboxLayout>
  </Page>
</template>

<script >
export default {};
</script>

We set the src prop to the URL of the image.

stretch is set to 'none' to disable stretching.

We can also the src to a path in the project. For instance, we can write:

<template>
  <Page>
    <ActionBar title="NativeScript App"></ActionBar>
    <FlexboxLayout flexDirection="column">
      <Image src="~/assets/images/NativeScript-Vue.png" stretch="none" />
    </FlexboxLayout>
  </Page>
</template>

<script >
export default {};
</script>

We can reference an image in the /src/assets/images folder with this path.

Also, we can reference an icon:

<template>
  <Page>
    <ActionBar title="NativeScript App"></ActionBar>
    <FlexboxLayout flexDirection="column">
      <Image src="res://icon" stretch="none" />
    </FlexboxLayout>
  </Page>
</template>

<script >
export default {};
</script>

A base64 string also works:

<template>
  <Page>
    <ActionBar title="NativeScript App"></ActionBar>
    <FlexboxLayout flexDirection="column">
      <Image
        src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4QDeRXhpZgAASUkqAAgAAAAGABIBAwABAAAAAQAAABoBBQABAAAAVgAAABsBBQABAAAAXgAAACgBAwABAAAAAgAAABMCAwABAAAAAQAAAGmHBAABAAAAZgAAAAAAAAA4YwAA6AMAADhjAADoAwAABwAAkAcABAAAADAyMTABkQcABAAAAAECAwCGkgcAFQAAAMAAAAAAoAcABAAAADAxMDABoAMAAQAAAP//AAACoAQAAQAAAMgAAAADoAQAAQAAAMgAAAAAAAAAQVNDSUkAAABQaWNzdW0gSUQ6IDIzAP/bAEMACAYGBwYFCAcHBwkJCAoMFA0MCwsMGRITDxQdGh8eHRocHCAkLicgIiwjHBwoNyksMDE0NDQfJzk9ODI8LjM0Mv/bAEMBCQkJDAsMGA0NGDIhHCEyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMv/CABEIAMgAyAMBIgACEQEDEQH/xAAbAAACAwEBAQAAAAAAAAAAAAAABAECAwUGB//EABcBAQEBAQAAAAAAAAAAAAAAAAABAgP/2gAMAwEAAhADEAAAAU21WN8nGVGZGmVWZGK040ej1Q6GbMxM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Y+P9H3iLy2i+XkfyhBXgMCrp81C1mmoLqjAOSFWxwR+450PbABaweoYAI21iX9e2FmRXhNRWgQXA/2Y/ENiLlrhDXscyyabBp9m0ie3lAX5HDHRUKRftW3zKqAPcjOelwYpllARvtQzio29eDgvu9/4QdukFlsYfxM4YK82dvnf2zBIXtAZB7q5YnlxGytffPj3ECuVysLoL+6DC/ppgBHx0Y/Rv6hBS3lsi34s+omMrarN/uD7lhgWwV/YPqUwAX7efw0PFSsQR8jUdx7y7I6YWly+0uDGL9Td9lRon3Pni8sXEkR9H9zHqu9MH7TF5OwMh4Imt2b1j/r2COs9o5vNLI2rErDUbQ9oua/3LShfZh9RJEdDym/YP8AcAigu224fpgEghG/7H+YI4Wdj/KenxHLbUvPD+Oh05ixL6alwY4S7ECgt0eJdgBwg7lru8nMCArZbA+piAguC8TJkGM29JBOsgGU5P7/ADLxqRoebZ9Qml/KmT2QVDeHIb++fzFDLqkun/YOmVvud/gofFYbiuGDpK3ExXKbgw3HEC7VcP8AjEFMGpuvE4iMgKbD3M1K9D3hwIgOVsiedQBgdSG4MuXLlxYRnEVRyw43L5uKo5mMXDU9I8QXAp66NYPiPwY/AhuLHeDHshzDUMMdxyR1H4nwfkdF0y3eO5eOjOIfE6v/AIBDXTXzEfidP//Z"
        stretch="none"
      />
    </FlexboxLayout>
  </Page>
</template>

<script >
export default {};
</script>

We can also display a font icon:

<template>
  <Page>
    <ActionBar title="NativeScript App"></ActionBar>
    <FlexboxLayout flexDirection="column">
      <Image src.decode="font://&#xf004;" class="fas" />
    </FlexboxLayout>
  </Page>
</template>

<script >
export default {};
</script>

We add the decode modifier to decode the icon font.

Conclusion

We can add a date picker, HTML view, frame and an image into our app with NativeScript Vue.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *