state-management
БесплатноБез исполняемых скриптовНе проверенTeaches Vue state management with stores, Pinia, and the Composition API. Use when you need to share and synchronize state across multiple components beyond…
от PatternsDev★ 261 звезда на GitHubОб этом скилле
State Management
Table of Contents
Vue components are the building blocks of Vue apps by allowing us to couple markup (HTML), logic (JS), and styles (CSS) within them.
When to Use
- Use this when you need to share reactive data between sibling or deeply nested components
- This is helpful for managing global application state beyond simple parent-child prop passing
Instructions
- Use props for parent-to-child data flow and custom events for child-to-parent communication
- Create a simple store using
reactive()for small applications - Use Pinia (the official Vue state management library) for larger apps needing devtools, plugins, and TypeScript support
- Choose the state management approach based on your app's complexity — don't over-engineer small apps
Details
Here's an example of a Single-File component that displays a series of numbers from a data property:
<template>
<div>
<h2>The numbers are {{ numbers }}!</h2>
</div>
</template>
<script setup>
import { ref } from "vue";
const numbers = ref([1, 2, 3]);
</script>
The ref() function prepares the component to be reactive. If a reactive property value that's being used in the template changes, the component view will re-render to show the change.
What if numbers was a data value that needed to be accessed from another component? If we want to share numbers between multiple components, numbers doesn't only become component-level data but also application-level data. This brings us to the topic of State Management - the management of application level data.
Props
Vue gives us the ability to use props to pass data from the parent down to the child. Using props is fairly simple. All we essentially need to do is bind a value to the prop attribute where the child component is being rendered.
ParentComponent:
<template>
<div>
<ChildComponent :numbers="numbers" />
</div>
</template>
<script setup>
import { ref } from "vue";
import ChildComponent from "./ChildComponent";
const numbers = ref([1, 2, 3]);
</script>
ChildComponent:
<template>
<div>
<h2>{{ numbers }}</h2>
</div>
</template>
<script setup>
const { numbers } = defineProps(["numbers"]);
</script>
Component Events
What if we needed to find a way to communicate information in the opposite direction? We can't use props since props can only be used to pass data in a uni-directional format (from parent down to child). To facilitate having the child component notify the parent about something, we can use custom events.
Custom events in Vue are dispatched as native CustomEvents and are used for communication between components.
ChildComponent:
<template>
<div>
<h2>{{ numbers }}</h2>
<input v-model="number" type="number" />
<button @click="$emit('number-added', Number(number))">
Add new number
</button>
</div>
</template>
<script setup>
const { numbers } = defineProps(["numbers"]);
</script>
ParentComponent:
<template>
<div>
<ChildComponent :numbers="numbers" @number-added="(n) => numbers.push(n)" />
</div>
</template>
<script setup>
import { ref } from "vue";
import ChildComponent from "./ChildComponent";
const numbers = ref([1, 2, 3]);
</script>
Simple State Management
We can use props to pass data downwards and custom events to send messages upwards. How would we be able to either pass data or facilitate communication between two different sibling components?
A simple way to manage application-level state is to create a store pattern that involves sharing a data store between components. The store can manage the state of our application as well as the methods that are responsible for changing the state.
import { reactive } from "vue";
export const store = reactive({
numbers: [1, 2, 3],
addNumber(newNumber) {
this.numbers.push(newNumber);
},
});
The store contains a numbers array and an addNumber method that accepts a payload and directly updates the store's numbers value.
With Vue 3.x, we're able to import and use the reactive() function to declare reactive state from a JavaScript object. When this reactive state gets changed with the addNumber() method, any component that uses this reactive state will automatically update!
NumberDisplay:
<template>
<div>
<h2>{{ store.numbers }}</h2>
</div>
</template>
<script setup>
import { store } from "../store.js";
</script>
NumberSubmit:
<template>
<div>
<input v-model="numberInput" type="number" />
<button @click="store.addNumber(numberInput)">Add new number</button>
</div>
</template>
<script setup>
import { ref } from "vue";
import { store } from "../store.js";
const numberInput = ref(0);
</script>
When we say components inte
Установить state-management в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл state-management?
Teaches Vue state management with stores, Pinia, and the Composition API. Use when you need to share and synchronize state across multiple components beyond what props and events can handle.
Как установить скилл state-management?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл state-management запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic