Vue

A Vue 3 cheat sheet with the most important concepts, reactivity, component system, routing, and more. Updated for the latest version and perfect for both beginners and advanced users.

#๐Ÿ“˜ Vue.js 3 NCS โ€“ Beginner to Advanced

#โš™๏ธ 1. Setup

#CDN (Quick Start)

<script src="https://unpkg.com/vue@3"></script>
<div id="app">{{ message }}</div>
<script>
  Vue.createApp({
    data() {
      return { message: 'Hello Vue!' };
    }
  }).mount('#app');
</script>

#Vite + Vue

npm create vite@latest my-vue-app --template vue
cd my-vue-app
npm install
npm run dev

#๐Ÿง  2. App Structure

#๐Ÿ“ฆ 3. Data, Methods, Template

#๐Ÿงฐ 4. Directives

#Example

<input v-model="name" />
<p v-if="name">Hi, {{ name }}!</p>
<ul>
  <li v-for="item in list" :key="item.id">{{ item }}</li>
</ul>

#๐Ÿช 5. Lifecycle Hooks

#๐ŸŽฏ 6. Events

#๐Ÿ” 7. Computed & Watch

#๐Ÿงฑ 8. Components

#Register + Use

app.component('Greeting', {
  props: ['name'],
  template: `<h1>Hello, {{ name }}!</h1>`
});
<Greeting name="Sumangal" />

#๐Ÿ”— 9. Props & Emits

#Props

props: {
  title: String,
  age: {
    type: Number,
    default: 18
  }
}

#Emit

this.$emit('custom-event', payload);

#๐Ÿ”„ 10. v-model with Components

#โš’ 11. Composition API

#๐ŸŒ 12. Vue Router

#router.js

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

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

export default createRouter({
  history: createWebHistory(),
  routes
});

#main.js

import { createApp } from 'vue';
import App from './App.vue';
import router from './router';

const app = createApp(App);
app.use(router).mount('#app');

#๐Ÿ“ฆ 13. Pinia (Vuex Alternative)

#store/counter.js

import { defineStore } from 'pinia';

export const useCounterStore = defineStore('counter', {
  state: () => ({ count: 0 }),
  actions: {
    increment() {
      this.count++;
    }
  }
});
const counter = useCounterStore();
counter.increment();

#๐ŸŽจ 14. Slots

#๐Ÿงช 15. Testing

#Vitest + Vue Test Utils

npm install vitest @vue/test-utils
import { mount } from '@vue/test-utils';
import MyComponent from '@/components/MyComponent.vue';

test('renders', () => {
  const wrapper = mount(MyComponent);
  expect(wrapper.text()).toContain('Hello');
});

#๐Ÿงผ 16. Best Practices

#๐Ÿ›  17. Dev Tools

#๐Ÿ“š 18. Official Resources