📖 DOC: Update dependencies in package.json and add Vue 3 cheat sheet

This commit is contained in:
sumangal44 committed 2025-06-13 08:36:13 +05:30
1 parent d1cc4625f8
commit 1870668b06
2 files changed
+344 -19

No files matched your search

+19 -19
View File
@@ -18,63 +18,63 @@
"version": "5.4.2"
},
"dependencies": {
"eslint": "^8.27.0",
"eslint": "^8.57.1",
"gulp": "^4.0.2",
"gulp-cli": "^2.3.0",
"gulp-ext-replace": "^0.3.0",
"gulp-htmlclean": "^2.7.22",
"gulp-htmlmin": "^5.0.1",
"gulp-minify-css": "^1.2.4",
"gulp-postcss": "^9.0.1",
"gulp-postcss": "^9.1.0",
"gulp-uglify-es": "^3.0.0",
"gulp-version-number": "^0.2.4",
"hexo": "^5.4.0",
"hexo": "^5.4.2",
"hexo-browsersync": "^0.3.0",
"hexo-cli": "^4.3.0",
"hexo-excerpt": "^1.2.1",
"hexo-cli": "^4.3.2",
"hexo-excerpt": "^1.3.1",
"hexo-filter-nofollow": "^2.0.2",
"hexo-generator-index": "^2.0.0",
"hexo-generator-sitemap": "^2.2.0",
"hexo-log": "^3.0.0",
"hexo-log": "^3.2.0",
"hexo-pagination": "^2.0.0",
"hexo-related-popular-posts": "^5.0.1",
"hexo-renderer-ejs": "^2.0.0",
"hexo-renderer-markdown-it": "^5.0.0",
"hexo-renderer-stylus": "^2.0.1",
"hexo-renderer-stylus": "^2.1.0",
"hexo-server": "^2.0.0",
"markdown-it-abbr": "^1.0.4",
"markdown-it-anchor": "^8.4.1",
"markdown-it-anchor": "^8.6.7",
"markdown-it-attrs": "^4.3.1",
"markdown-it-checkbox": "^1.1.0",
"markdown-it-emoji": "^2.0.0",
"markdown-it-emoji": "^2.0.2",
"markdown-it-footnote": "^3.0.3",
"markdown-it-highlight-lines": "^1.0.2",
"markdown-it-highlightjs": "^3.5.0",
"markdown-it-highlightjs": "^3.6.0",
"markdown-it-ins": "^3.0.1",
"markdown-it-multimd-table": "^4.1.1",
"markdown-it-multimd-table": "^4.2.3",
"markdown-it-shortcode-tag": "^1.1.0",
"markdown-it-sub": "^1.0.0",
"markdown-it-sup": "^1.0.0",
"markdown-it-task-lists": "^2.1.1"
},
"devDependencies": {
"autoprefixer": "^10.4.0",
"autoprefixer": "^10.4.21",
"gulp-clean-css": "^4.3.0",
"gulp-filesize": "^0.0.6",
"gulp-javascript-obfuscator": "^1.1.6",
"gulp-replace": "^1.1.3",
"gulp-replace": "^1.1.4",
"gulp-rev": "^9.0.0",
"gulp-terser": "^2.1.0",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.4",
"postcss": "^8.5.5",
"postcss-cli": "^9.1.0",
"postcss-import": "^14.0.2",
"postcss-minify": "^1.1.0",
"prettier": "^3.2.5",
"postcss-import": "^14.1.0",
"postcss-minify": "^1.2.0",
"prettier": "^3.5.3",
"prettier-plugin-tailwindcss": "^0.5.14",
"sync-request": "^6.1.0",
"tailwindcss": "^3.0.1",
"tailwindcss-animate": "^1.0.5",
"tailwindcss": "^3.4.17",
"tailwindcss-animate": "^1.0.7",
"tailwindcss-cli": "^0.1.2"
}
}
+325
View File
@@ -0,0 +1,325 @@
---
title: Vue
date: 2025-06-13 14:45:00
background: bg-[#43CF96]
tags:
- vue
- web
categories:
- Programming
intro: |
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.
plugins:
- copyCode
- runCode
---
## 📘 Vue.js 3 Cheatsheet – Beginner to Advanced
> The ultimate reference for mastering Vue 3.
## ⚙️ 1. Setup
### CDN (Quick Start)
```html
<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
```bash
npm create vite@latest my-vue-app --template vue
cd my-vue-app
npm install
npm run dev
```
## 🧠 2. App Structure
```
src/
├─ components/
├─ views/
├─ App.vue
├─ main.js
```
## 📦 3. Data, Methods, Template
```js
data() {
return {
count: 0,
message: "Welcome!"
};
},
methods: {
increment() {
this.count++;
}
}
```
```html
<h1>{{ message }}</h1>
<button @click="increment">+</button>
```
## 🧰 4. Directives
| Directive | Purpose |
| --------------- | ----------------------- |
| `v-bind` / `:` | Bind attributes |
| `v-model` | Two-way binding |
| `v-if / v-else` | Conditional rendering |
| `v-show` | Toggle visibility |
| `v-for` | List rendering |
| `v-on` / `@` | Event handling |
| `v-slot` | Named/Scoped slot usage |
### Example
```html
<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
```js
created() {},
mounted() {},
updated() {},
unmounted() {}
```
## 🎯 6. Events
```html
<button @click="sayHi">Click</button>
<input @keyup.enter="submit" />
```
## 🔁 7. Computed & Watch
```js
computed: {
reversed() {
return this.message.split('').reverse().join('');
}
},
watch: {
count(newVal, oldVal) {
console.log(`Count changed from ${oldVal} to ${newVal}`);
}
}
```
## 🧱 8. Components
### Register + Use
```js
app.component("Greeting", {
props: ["name"],
template: `<h1>Hello, {{ name }}!</h1>`
});
```
```html
<Greeting name="Sumangal" />
```
## 🔗 9. Props & Emits
### Props
```js
props: {
title: String,
age: {
type: Number,
default: 18
}
}
```
### Emit
```js
this.$emit("custom-event", payload);
```
## 🔄 10. v-model with Components
```js
props: ['modelValue'],
emits: ['update:modelValue']
```
```html
<input
:value="modelValue"
@input="$emit('update:modelValue', $event.target.value)"
/>
```
## ⚒ 11. Composition API
```js
import { ref, computed } from "vue";
export default {
setup() {
const count = ref(0);
const double = computed(() => count.value * 2);
const increment = () => count.value++;
return { count, double, increment };
}
};
```
## 🌐 12. Vue Router
```bash
npm install vue-router
```
### router.js
```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
```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)
```bash
npm install pinia
```
### store/counter.js
```js
import { defineStore } from "pinia";
export const useCounterStore = defineStore("counter", {
state: () => ({ count: 0 }),
actions: {
increment() {
this.count++;
}
}
});
```
```js
const counter = useCounterStore();
counter.increment();
```
## 🎨 14. Slots
```html
<!-- Default -->
<slot></slot>
<!-- Named -->
<slot name="header"></slot>
<!-- Scoped -->
<slot :user="user"></slot>
```
## 🧪 15. Testing
### Vitest + Vue Test Utils
```bash
npm install vitest @vue/test-utils
```
```js
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
* Use `ref()` for primitives, `reactive()` for objects
* Use `<script setup>` syntax in SFCs
* Break UI into small, reusable components
* Always define `key` in `v-for`
* Use slots for flexible composition
## 🛠 17. Dev Tools
* 🧩 [Vue DevTools](https://devtools.vuejs.org/)
* 🧠 [Volar](https://github.com/vuejs/language-tools) for VSCode
* ⚡ [Vite](https://vitejs.dev) for fast dev environment
## 📚 18. Official Resources
* 📘 [Vue Docs](https://vuejs.org)
* 🧭 [Router Docs](https://router.vuejs.org)
* 📦 [Pinia Docs](https://pinia.vuejs.org)
* 🧪 [Composition API FAQ](https://vuejs.org/guide/extras/composition-api-faq.html)