vue.js cheatsheet, vue.js tutorial, vue directives, vue components, vue data binding, vue computed properties, vue lifecycle hooks, vue router example, vue beginner guide, vue.js quick reference
vue.js cheatsheet, vue.js tutorial, vue directives, vue components, vue data binding, vue computed properties, vue lifecycle hooks, vue router example, vue beginner guide, vue.js quick reference

Vue.js Cheatsheet — The Ultimate Developer Reference

Vue.js is a progressive JavaScript framework for building dynamic user interfaces and single-page applications (SPAs).
It’s lightweight, fast, and easy to integrate into existing web projects — making it one of the most popular front-end frameworks in modern development.

This Vue.js Cheatsheet is your quick go-to reference for writing clean, efficient Vue code — perfect for both beginners and experienced developers.


What is Vue.js?

Vue.js is an open-source front-end JavaScript framework designed to make UI development simple and flexible.
It uses a declarative and component-based approach, allowing developers to easily manage data, logic, and presentation.

Key Features:

  • Reactive Data Binding
  • Virtual DOM Rendering
  • Component-based Architecture
  • Two-way Data Binding
  • Transitions and Animations
  • Routing and State Management

Setting Up Vue.js

1. Using CDN

<script src="https://unpkg.com/vue@3"></script>

2. Creating a Vue App

<div id="app">
  {{ message }}
</div>

<script>
const app = Vue.createApp({
  data() {
    return {
      message: "Hello Vue.js!"
    }
  }
});
app.mount('#app');
</script>

Vue.js Template Syntax

SyntaxDescriptionExample
{{ }}Data Binding{{ message }}
v-bindBind HTML attributesv-bind:src="imageURL"
v-modelTwo-way data bindingv-model="username"
v-if / v-elseConditional rendering<p v-if="loggedIn">Welcome</p>
v-forLoop through data<li v-for="item in items">{{ item }}</li>
v-onEvent listenerv-on:click="sayHello" or @click="sayHello"
vue.js cheatsheet, vue.js tutorial, vue directives, vue components, vue data binding, vue computed properties, vue lifecycle hooks, vue router example, vue beginner guide, vue.js quick reference

Vue.js Directives

DirectivePurposeExample
v-textUpdates textContent<p v-text="message"></p>
v-htmlInserts HTML content<div v-html="rawHTML"></div>
v-showShow/Hide element<p v-show="isVisible">Visible</p>
v-ifConditional rendering<div v-if="isLoggedIn"></div>
v-else-ifConditional alternative<div v-else-if="hasAccess"></div>
v-elseFallback condition<div v-else>No Access</div>
v-forRender list<li v-for="(user, index) in users">{{ user.name }}</li>

Vue.js Event Handling

<button @click="increment">Add Count</button>
<p>Count: {{ count }}</p>

<script>
const app = Vue.createApp({
  data() {
    return { count: 0 }
  },
  methods: {
    increment() {
      this.count++
    }
  }
});
app.mount('#app');
</script>

Vue.js Computed Properties

const app = Vue.createApp({
  data() {
    return {
      firstName: 'John',
      lastName: 'Doe'
    }
  },
  computed: {
    fullName() {
      return `${this.firstName} ${this.lastName}`;
    }
  }
});

Vue.js Watchers

watch: {
  count(newVal, oldVal) {
    console.log(`Count changed from ${oldVal} to ${newVal}`);
  }
}

Watchers are ideal for reacting to data changes — such as API calls or animations.


Vue.js Components

Global Component

app.component('user-card', {
  props: ['name'],
  template: `<div>Hello, {{ name }}</div>`
});

Usage

<user-card name="Alice"></user-card>

Vue Lifecycle Hooks

HookWhen Triggered
beforeCreateBefore data initialization
createdAfter data initialization
beforeMountBefore mounting DOM
mountedAfter mounting DOM
beforeUpdateBefore re-render
updatedAfter re-render
beforeUnmountBefore component destruction
unmountedAfter destruction

Vue.js Conditional Rendering

<p v-if="isLoggedIn">Welcome back!</p>
<p v-else>Please log in</p>

Vue.js Lists

<ul>
  <li v-for="(fruit, index) in fruits" :key="index">{{ fruit }}</li>
</ul>

Vue.js Forms and v-model

<input v-model="username" placeholder="Enter your name">
<p>Hello, {{ username }}</p>

Vue.js Class & Style Binding

<div :class="{ active: isActive }"></div>
<div :style="{ color: textColor, fontSize: fontSize + 'px' }"></div>

Vue Router Example

Install:

npm install vue-router

Setup:

import { createRouter, createWebHistory } from 'vue-router';
import Home from './components/Home.vue';
import About from './components/About.vue';

const routes = [
  { path: '/', component: Home },
  { path: '/about', component: About }
];

const router = createRouter({
  history: createWebHistory(),
  routes
});

export default router;

Vue CLI Quick Commands

CommandDescription
npm install -g @vue/cliInstall Vue CLI
vue create project-nameCreate new Vue project
npm run serveRun local dev server
npm run buildBuild for production

Vue 3 Composition API Example

import { createApp, ref } from 'vue';

const App = {
  setup() {
    const count = ref(0);
    const increment = () => count.value++;
    return { count, increment };
  }
};
createApp(App).mount('#app');

Best Practices for Vue.js

✅ Use computed instead of long inline expressions
✅ Prefer components for reusable UI blocks
✅ Manage routes with Vue Router
✅ Use Vuex or Pinia for state management
✅ Keep template markup clean and minimal



FAQ — Vue.js Cheatsheet

Q1: What is Vue.js mainly used for?
Vue.js is used to build responsive, component-based web interfaces and single-page applications.

Q2: Is Vue.js easier than React?
Yes, Vue.js is generally considered easier for beginners due to its simpler syntax and smaller learning curve.

Q3: Can Vue.js work with Node.js?
Yes. Vue.js handles the frontend, while Node.js powers the backend for full-stack development.

Q4: What are Vue.js directives?
Directives like v-if, v-for, v-bind, and v-model are special attributes that control DOM behavior.

Q5: What’s new in Vue 3?
Vue 3 introduces the Composition API, Teleport, and improved performance with a smaller bundle size.

Related Article
Machine Learning Cheatsheet (Unsupervised & Reinforcement Learning)

Machine Learning (ML) is a crucial part of artificial intelligence, enabling systems to automatically learn from data.This Machine Learning Cheatsheet Read more

HTML Cheat Sheet — Reference Guide to HTML Tags, Attributes, and Examples

HTML cheat sheet, HTML tags reference, HTML attributes list, HTML examples for beginners, semantic HTML guide, HTML forms tutorial, HTML Read more

Python Cheat Sheet — Complete Syntax Reference and Programming Examples

This Python Cheat Sheet is your quick reference guide for writing efficient Python code. Whether you’re preparing for coding interviews, Read more

PHP Cheat Sheet — Complete Syntax Reference and Programming Examples for Beginners

PHP Cheat Sheet — Complete Syntax Reference & Examples This PHP Cheat Sheet serves as a quick, structured reference for Read more

JavaScript Cheat Sheet — Complete ES6 Syntax, Functions, and DOM Methods with Examples

JavaScript Cheat Sheet — Complete Syntax Reference & Examples JavaScript is the core scripting language of the web, enabling interactivity, Read more

CSS Cheat Sheet — Complete CSS3 Selectors, Properties, and Layout Examples

CSS Cheat Sheet — Complete CSS3 Syntax, Selectors & Layout Examples Cascading Style Sheets (CSS) is the language used to Read more

Java Cheat Sheet — Complete Java Syntax, Data Types, Loops, and OOP Concepts for Beginners

Java Cheat Sheet — Complete Java Syntax, Classes, and Examples Java is a powerful, object-oriented programming language widely used for Read more

HTML5 Cheat Sheet — Complete Tag Reference & Examples

HTML5 is the core markup language of the modern web, used to structure content such as text, images, forms, and Read more

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments