diff --git a/skills/VUE.md b/skills/VUE.md new file mode 100644 index 0000000..5d19406 --- /dev/null +++ b/skills/VUE.md @@ -0,0 +1,412 @@ +# Vue.js Basics + +Guide Vue.js development using Vue 3 loaded via CDN. **No build process.** No Vite, no npm, no .vue single-file components. Import Vue and any other libraries via ` + + + +``` + +Key points: +- Vue script tag goes before `app.js` so Vue is available when your code runs. +- The `
` is where Vue mounts — everything inside it becomes a Vue template. +- Use `vue.global.js` (not `vue.esm-browser.js`) for script-tag usage. + +--- + +## 2. Creating an App + +### Minimal app + +```js +// js/app.js +const app = Vue.createApp({ + data() { + return { + message: "Hello, Vue!", + }; + }, +}); + +app.mount("#app"); +``` + +```html + +

{{ message }}

+``` + +### Options explained + +| Option | Purpose | +|--------|---------| +| `data()` | Returns an object of reactive state. Must be a function. | +| `methods` | Object of functions the template can call. | +| `computed` | Object of derived values that update automatically. | +| `watch` | Object of functions that run when a data property changes. | +| `mounted()` | Lifecycle hook — runs after the app is inserted into the page. | + +--- + +## 3. Template Basics + +### Text interpolation + +```html +

{{ message }}

+

{{ count + 1 }}

+

{{ items.length > 0 ? "Has items" : "Empty" }}

+``` + +Double curly braces `{{ }}` output the value of a JavaScript expression. The expression is reactive — the page updates automatically when the data changes. + +### Attribute binding — `v-bind` (shorthand `:`) + +```html + +Link + + +Link + + +``` + +Use `:` to bind any HTML attribute to a data property. + +### Conditional rendering — `v-if` / `v-else-if` / `v-else` + +```html +

No items yet.

+

One item.

+

{{ items.length }} items.

+``` + +`v-if` removes or adds elements from the DOM. Use `v-show` instead if you need to toggle visibility frequently (it uses CSS `display: none`). + +### List rendering — `v-for` + +```html + +``` + +**Always provide a `:key`** — Vue uses it to track which items changed. Use a unique identifier, not the array index. + +### Two-way binding — `v-model` + +```html + +

You typed: {{ searchQuery }}

+``` + +`v-model` syncs an input's value with a data property. Works on ``, `