This skill is organized to match the Vuex official documentation structure (https://vuex.vuejs.org/zh/, https://vuex.vuejs.org/zh/guide/, https://vuex.vuejs.org/zh/api/). When working with Vuex:
- Identify the topic from the user's request:
- Installation/ๅฎ่ฃ
โ examples/guide/installation.md
- Quick Start/ๅฟซ้ๅผๅง โ examples/guide/quick-start.md
- Core Concepts/ๆ ธๅฟๆฆๅฟต โ examples/core-concepts/
- Advanced/้ซ็บง โ examples/advanced/
- API/API ๆๆกฃ โ api/
- Load the appropriate example file from the
examples/ directory:
Guide (ไฝฟ็จๆๅ):
- examples/guide/intro.md - Introduction to Vuex
- examples/guide/installation.md - Installation guide
- examples/guide/quick-start.md - Quick start guide
- examples/guide/what-is-vuex.md - What is Vuex
Core Concepts (ๆ ธๅฟๆฆๅฟต):
- examples/core-concepts/state.md - State
- examples/core-concepts/getters.md - Getters
- examples/core-concepts/mutations.md - Mutations
- examples/core-concepts/actions.md - Actions
- examples/core-concepts/modules.md - Modules
Advanced (้ซ็บง):
- examples/advanced/plugins.md - Plugins
- examples/advanced/strict-mode.md - Strict mode
- examples/advanced/form-handling.md - Form handling
- examples/advanced/testing.md - Testing
- examples/advanced/hot-reload.md - Hot reload
- Follow the specific instructions in that example file for syntax, structure, and best practices
Important Notes:
- Vuex is for Vue 2.x
- Store is the central state management
- State is reactive
- Mutations are synchronous
- Actions are asynchronous
- Each example file includes key concepts, code examples, and key points
- Reference API documentation in the
api/ directory when needed:
- api/store-api.md - Store API
- api/state-api.md - State API
- api/getters-api.md - Getters API
- api/mutations-api.md - Mutations API
- api/actions-api.md - Actions API
- api/modules-api.md - Modules API
- api/plugins-api.md - Plugins API
- Use templates from the
templates/ directory:
- templates/installation.md - Installation templates
- templates/store-setup.md - Store setup templates
- templates/component-usage.md - Component usage templates
1. Understanding Vuex
Vuex is a state management pattern and library for Vue.js applications. It serves as a centralized store for all the components in an application.
Key Concepts:
- Store: Centralized state container
- State: Application state (data)
- Getters: Computed properties for store
- Mutations: Synchronous state changes
- Actions: Asynchronous operations
- Modules: Store organization
2. Installation
Using npm:
```bash
npm install vuex@3
```
Using yarn:
```bash
yarn add vuex@3
```
Using CDN:
```html
```
3. Basic Setup
```javascript
// store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment(state) {
state.count++
}
}
})
export default store
```
```javascript
// main.js
import Vue from 'vue'
import store from './store'
new Vue({
store,
render: h => h(App)
}).$mount('#app')
```
Doc mapping (one-to-one with official documentation)
examples/guide/ or examples/getting-started/ โ https://vuex.vuejs.org/zh/guide/api/ โ https://vuex.vuejs.org/zh/api/