1. Home
  2. /
  3. Nativescript
  4. /
  5. Vue Counter Example

Vue Counter Example - Nativescript Typing CST Test

Loading…

Vue Counter Example — Nativescript Code

Demonstrates a simple counter layout using NativeScript Vue components and Vue.js for interactivity.

<template>
	<Page class="page" :class="{ 'dark-theme': isDark }">
		<ActionBar title="NativeScript Counter" class="action-bar" />
		<StackLayout class="container" horizontalAlignment="center" verticalAlignment="center">
		<Label :text="`Counter: ${count}`" class="counter-text" />
		<Button text="+" @tap="increment" class="btn-primary" />
		<Button text="-" @tap="decrement" class="btn-danger" />
		<Button text="Reset" @tap="reset" class="btn-secondary" />
		<Button text="Switch Theme" @tap="toggleTheme" class="btn-warning" />
		</StackLayout>
	</Page>
</template>

<script>
import { ref } from 'vue';
export default {
	setup() {
		const count = ref(0);
		const isDark = ref(false);

		const increment = () => count.value++;
		const decrement = () => count.value--;
		const reset = () => count.value = 0;
		const toggleTheme = () => { isDark.value = !isDark.value; };

		return { count, increment, decrement, reset, toggleTheme, isDark };
	}
};
</script>

<style scoped>
	.page { background-color: #fff; color: #000; }
	.dark-theme { background-color: #333; color: #fff; }
	.container { margin-top: 50px; text-align: center; }
	.btn-primary, .btn-danger, .btn-secondary { margin: 5px; }
	.btn-warning { margin: 10px 0; }
	.counter-text { font-size: 24px; margin-bottom: 10px; }
</style>

Nativescript Language Guide

NativeScript is an open-source framework for building truly native mobile applications using JavaScript, TypeScript, Angular, or Vue. It allows developers to write cross-platform apps that access native APIs directly without using WebViews.

Primary Use Cases

  • ▸Cross-platform native apps for iOS and Android
  • ▸Enterprise apps requiring native performance
  • ▸Apps needing access to full device APIs and native UI
  • ▸Rapid prototyping of native mobile apps
  • ▸Integration with Angular, Vue, or plain TypeScript/JavaScript front-end

Notable Features

  • ▸Direct access to native UI components
  • ▸Cross-platform with single codebase
  • ▸Supports Angular, Vue, and plain TypeScript/JavaScript
  • ▸Large ecosystem of plugins for device APIs
  • ▸Open-source and actively maintained

Origin & Creator

Developed by Progress in 2015, NativeScript was created to bridge the gap between web development skills and native mobile development, providing a cross-platform solution without relying on WebViews.

Industrial Note

Perfect for enterprises and startups seeking cross-platform apps with fully native performance while leveraging existing JavaScript/TypeScript skills.

More Nativescript Typing Exercises

NativeScript Vue Step CounterNativeScript Vue Auto Increment CounterNativeScript Vue Dark Mode CounterNativeScript Vue Multi CounterNativeScript Vue Toggle CounterNativeScript Vue Countdown TimerNativeScript Vue Counter With Alert

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher