Nuxt.js Counter with watchEffect - Nuxt-js Typing CST Test
Loading…
Nuxt.js Counter with watchEffect — Nuxt-js Code
Uses watchEffect to persist count automatically.
<template>
<div :class="isDark ? 'dark-theme' : 'light-theme'">
<h2>Counter: {{ count }}</h2>
<button @click="increment">+</button>
<button @click="decrement">-</button>
<button @click="reset">Reset</button>
<button @click="toggleTheme">Switch Theme</button>
</div>
</template>
<script setup>
import { ref, watchEffect, onMounted } from 'vue';
const count = ref(0);
const isDark = ref(false);
onMounted(() => {
const saved = localStorage.getItem('count');
if (saved) count.value = parseInt(saved,10);
});
watchEffect(() => localStorage.setItem('count', count.value));
const increment = () => count.value++;
const decrement = () => count.value--;
const reset = () => count.value=0;
const toggleTheme = () => isDark.value = !isDark.value;
</script>
<style>
.dark-theme { background-color: #222; color: #eee; }
.light-theme { background-color: #fff; color: #000; }
</style>Nuxt-js Language Guide
Nuxt.js is a high-level framework built on top of Vue.js for creating modern web applications with SSR, SSG, API integration, routing, performance optimizations, and full-stack capabilities using server routes. It emphasizes flexibility, DX, and hybrid rendering.
Primary Use Cases
- ▸SEO-focused websites
- ▸Static or hybrid-rendered sites
- ▸Full-stack Vue apps with API routes
- ▸E-commerce and SaaS dashboards
- ▸Enterprise Vue applications
Notable Features
- ▸File-based routing
- ▸Vue Server Components (Nuxt Islands)
- ▸Universal rendering (SSR/SSG)
- ▸Nitro server engine + API routes
- ▸Auto-imports + module ecosystem
Origin & Creator
Created by the Chopin brothers (Alexandre & Sébastien Chopin) and released in 2016, maintained by the NuxtLabs team.
Industrial Note
Nuxt excels in SEO-heavy websites, fast content sites, dashboards, PWAs, internationalized apps, and full-stack Vue-based platforms.