1. Home
  2. /
  3. Vue-js
  4. /
  5. Vue.js Counter with Toggle Theme Using Class Binding

Vue.js Counter with Toggle Theme Using Class Binding - Vue-js Typing CST Test

Loading…

Vue.js Counter with Toggle Theme Using Class Binding — Vue-js Code

Demonstrates dynamic class binding for dark/light theme in Vue.js.

<template>
	<div :class="themeClass">
		<h2>Counter: {{ count }}</h2>
		<button @click="increment">+</button>
		<button @click="decrement">-</button>
		<button @click="toggleTheme">Toggle Theme</button>
	</div>
</template>

<script>
export default {
	data() { return { count: 0, isDark: false }; },
	computed: { themeClass() { return this.isDark ? 'dark-theme' : 'light-theme'; } },
	methods: { increment() { this.count++; }, decrement() { this.count--; }, toggleTheme() { this.isDark = !this.isDark; } }
};
</script>

Vue-js Language Guide

Vue.js is a progressive, open-source JavaScript framework for building user interfaces and single-page applications. It emphasizes simplicity, declarative rendering, and reactive data binding.

Primary Use Cases

  • ▸Single-page applications (SPAs)
  • ▸Interactive web interfaces and dashboards
  • ▸Progressive web apps (PWAs)
  • ▸Front-end integration for multi-page apps
  • ▸Rapid prototyping of UI components

Notable Features

  • ▸Reactive data binding with a virtual DOM
  • ▸Component-based architecture
  • ▸Vue CLI for project scaffolding
  • ▸Single-file components (.vue files) with scoped styles
  • ▸Integration with Vuex for state management

Origin & Creator

Created in 2014 by Evan You, a former Google engineer, inspired by Angular but with a simpler core.

Industrial Note

Vue.js is specialized for building modern front-end web applications and integrating into existing projects incrementally.

More Vue-js Typing Exercises

Vue.js Counter ComponentVue.js Counter with Computed PropertyVue.js Counter with WatcherVue.js Counter with LocalStorageVue.js Counter with PropsVue.js Counter with Event EmissionVue.js Counter with Watch and Class BindingVue.js Counter with SlotsVue.js Counter with Mounted Hook

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher