vuex-vue2
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWhen to use this skill
何时使用此技能
Use this skill whenever the user wants to:
- Install and set up Vuex in a Vue 2 project
- Manage application state with Vuex
- Use Vuex store in Vue components
- Understand Vuex core concepts (state, getters, mutations, actions)
- Use Vuex modules for large applications
- Handle Vuex plugins and devtools
- Understand Vuex API and methods
- Troubleshoot Vuex issues
当用户有以下需求时,可使用此技能:
- 在Vue 2项目中安装和配置Vuex
- 使用Vuex管理应用状态
- 在Vue组件中使用Vuex store
- 理解Vuex核心概念(state、getters、mutations、actions)
- 在大型应用中使用Vuex modules
- 处理Vuex插件和开发者工具
- 理解Vuex API和方法
- 排查Vuex相关问题
How to use this skill
如何使用此技能
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/
- Installation/安装 →
-
Load the appropriate example file from thedirectory:
examples/Guide (使用指南):- - Introduction to Vuex
examples/guide/intro.md - - Installation guide
examples/guide/installation.md - - Quick start guide
examples/guide/quick-start.md - - What is Vuex
examples/guide/what-is-vuex.md
Core Concepts (核心概念):- - State
examples/core-concepts/state.md - - Getters
examples/core-concepts/getters.md - - Mutations
examples/core-concepts/mutations.md - - Actions
examples/core-concepts/actions.md - - Modules
examples/core-concepts/modules.md
Advanced (高级):- - Plugins
examples/advanced/plugins.md - - Strict mode
examples/advanced/strict-mode.md - - Form handling
examples/advanced/form-handling.md - - Testing
examples/advanced/testing.md - - Hot reload
examples/advanced/hot-reload.md
-
Follow the specific instructions in that example file for syntax, structure, and best practicesImportant 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 thedirectory when needed:
api/- - Store API
api/store-api.md - - State API
api/state-api.md - - Getters API
api/getters-api.md - - Mutations API
api/mutations-api.md - - Actions API
api/actions-api.md - - Modules API
api/modules-api.md - - Plugins API
api/plugins-api.md
-
Use templates from thedirectory:
templates/- - Installation templates
templates/installation.md - - Store setup templates
templates/store-setup.md - - Component usage templates
templates/component-usage.md
本技能的组织结构与Vuex官方文档结构一致(https://vuex.vuejs.org/zh/、https://vuex.vuejs.org/zh/guide/、https://vuex.vuejs.org/zh/api/)。使用Vuex时:
-
从用户的请求中确定主题:
- 安装 →
examples/guide/installation.md - 快速开始 →
examples/guide/quick-start.md - 核心概念 →
examples/core-concepts/ - 高级 →
examples/advanced/ - API文档 →
api/
- 安装 →
-
从目录中加载对应的示例文件:
examples/使用指南:- - Vuex介绍
examples/guide/intro.md - - 安装指南
examples/guide/installation.md - - 快速开始指南
examples/guide/quick-start.md - - 什么是Vuex
examples/guide/what-is-vuex.md
核心概念:- - State
examples/core-concepts/state.md - - Getters
examples/core-concepts/getters.md - - Mutations
examples/core-concepts/mutations.md - - Actions
examples/core-concepts/actions.md - - Modules
examples/core-concepts/modules.md
高级:- - Plugins
examples/advanced/plugins.md - - 严格模式
examples/advanced/strict-mode.md - - 表单处理
examples/advanced/form-handling.md - - 测试
examples/advanced/testing.md - - 热重载
examples/advanced/hot-reload.md
-
遵循示例文件中的具体说明,包括语法、结构和最佳实践重要说明:
- Vuex适用于Vue 2.x
- Store是集中式状态管理容器
- State是响应式的
- Mutations是同步操作
- Actions是异步操作
- 每个示例文件都包含核心概念、代码示例和关键点
-
必要时参考目录中的API文档:
api/- - Store API
api/store-api.md - - State API
api/state-api.md - - Getters API
api/getters-api.md - - Mutations API
api/mutations-api.md - - Actions API
api/actions-api.md - - Modules API
api/modules-api.md - - Plugins API
api/plugins-api.md
-
使用目录中的模板:
templates/- - 安装模板
templates/installation.md - - Store配置模板
templates/store-setup.md - - 组件使用模板
templates/component-usage.md
1. Understanding Vuex
1. 理解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
Vuex是Vue.js应用的状态管理模式和库,作为应用中所有组件的集中式存储。
核心概念:
- Store: 集中式状态容器
- State: 应用状态(数据)
- Getters: Store的计算属性
- Mutations: 同步状态变更
- Actions: 异步操作
- Modules: Store的组织方式
2. Installation
2. 安装
Using npm:
bash
npm install vuex@3Using yarn:
bash
yarn add vuex@3Using CDN:
html
<script src="https://unpkg.com/vuex@3"></script>使用npm:
bash
npm install vuex@3使用yarn:
bash
yarn add vuex@3使用CDN:
html
<script src="https://unpkg.com/vuex@3"></script>3. Basic Setup
3. 基础配置
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 storejavascript
// main.js
import Vue from 'vue'
import store from './store'
new Vue({
store,
render: h => h(App)
}).$mount('#app')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 storejavascript
// 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)
文档映射(与官方文档一一对应)
- or
examples/guide/→ https://vuex.vuejs.org/zh/guide/examples/getting-started/ - → https://vuex.vuejs.org/zh/api/
api/
- 或
examples/guide/→ https://vuex.vuejs.org/zh/guide/examples/getting-started/ - → https://vuex.vuejs.org/zh/api/
api/
Examples and Templates
示例与模板
This skill includes detailed examples organized to match the official documentation structure. All examples are in the directory (see mapping above).
examples/To use examples:
- Identify the topic from the user's request
- Load the appropriate example file from the mapping above
- Follow the instructions, syntax, and best practices in that file
- Adapt the code examples to your specific use case
To use templates:
- Reference templates in directory for common scaffolding
templates/ - Adapt templates to your specific needs and coding style
本技能包含详细的示例,其组织结构与官方文档一致。所有示例都位于目录中(见上方映射)。
examples/使用示例的方法:
- 从用户的请求中确定主题
- 根据上方映射加载对应的示例文件
- 遵循文件中的说明、语法和最佳实践
- 根据具体使用场景调整代码示例
使用模板的方法:
- 参考目录中的模板进行常见脚手架搭建
templates/ - 根据具体需求和编码风格调整模板
API Reference
API参考
Detailed API documentation is available in the directory, organized to match the official Vuex API documentation structure (https://vuex.vuejs.org/zh/api/):
api/详细的API文档位于目录中,组织结构与Vuex官方API文档一致(https://vuex.vuejs.org/zh/api/):
api/Store API (api/store-api.md
)
api/store-api.mdStore API (api/store-api.md
)
api/store-api.md- Store constructor options
- Store instance properties
- Store instance methods
- Store构造函数选项
- Store实例属性
- Store实例方法
State API (api/state-api.md
)
api/state-api.mdState API (api/state-api.md
)
api/state-api.md- State definition
- State access
- State reactivity
- State定义
- State访问
- State响应式
Getters API (api/getters-api.md
)
api/getters-api.mdGetters API (api/getters-api.md
)
api/getters-api.md- Getter definition
- Getter access
- Getter arguments
- Getter定义
- Getter访问
- Getter参数
Mutations API (api/mutations-api.md
)
api/mutations-api.mdMutations API (api/mutations-api.md
)
api/mutations-api.md- Mutation definition
- Mutation commit
- Mutation payload
- Mutation定义
- Mutation提交
- Mutation载荷
Actions API (api/actions-api.md
)
api/actions-api.mdActions API (api/actions-api.md
)
api/actions-api.md- Action definition
- Action dispatch
- Action context
- Action定义
- Action分发
- Action上下文
Modules API (api/modules-api.md
)
api/modules-api.mdModules API (api/modules-api.md
)
api/modules-api.md- Module definition
- Module namespacing
- Module registration
- Module定义
- Module命名空间
- Module注册
Plugins API (api/plugins-api.md
)
api/plugins-api.mdPlugins API (api/plugins-api.md
)
api/plugins-api.md- Plugin definition
- Plugin usage
- Built-in plugins
To use API reference:
- Identify the API you need help with
- Load the corresponding API file from the directory
api/ - Find the API signature, parameters, return type, and examples
- Reference the linked example files for detailed usage patterns
- All API files include links to relevant example files in the directory
examples/
- Plugin定义
- Plugin使用
- 内置插件
使用API参考的方法:
- 确定需要帮助的API
- 从目录中加载对应的API文件
api/ - 查找API签名、参数、返回类型和示例
- 参考链接的示例文件获取详细使用模式
- 所有API文件都包含指向目录中相关示例文件的链接
examples/
Best Practices
最佳实践
- Use mutations for synchronous changes: Mutations must be synchronous
- Use actions for async operations: Actions can contain async operations
- Keep state normalized: Avoid nested state structures
- Use modules for large apps: Organize store with modules
- Use getters for computed state: Derive state with getters
- Follow naming conventions: Use consistent naming patterns
- Use TypeScript: Leverage TypeScript for type safety
- 使用mutations处理同步变更:Mutations必须是同步的
- 使用actions处理异步操作:Actions可以包含异步操作
- 保持状态规范化:避免嵌套状态结构
- 大型应用使用modules:用modules组织Store
- 使用getters处理计算状态:通过getters派生状态
- 遵循命名规范:使用一致的命名模式
- 使用TypeScript:利用TypeScript实现类型安全
Resources
资源
- Official Documentation: https://vuex.vuejs.org/zh/
- Guide: https://vuex.vuejs.org/zh/guide/
- API Documentation: https://vuex.vuejs.org/zh/api/
- GitHub Repository: https://github.com/vuejs/vuex
- 官方文档: https://vuex.vuejs.org/zh/
- 指南: https://vuex.vuejs.org/zh/guide/
- API文档: https://vuex.vuejs.org/zh/api/
- GitHub仓库: https://github.com/vuejs/vuex
Keywords
关键词
Vuex, vuex, Vue 2, state management, 状态管理, store, state, getters, mutations, actions, modules, 存储, 状态, 获取器, 变更, 动作, 模块, Vuex store, Vuex state, Vuex getters, Vuex mutations, Vuex actions, Vuex modules, Vuex plugins, centralized state, reactive state, synchronous mutations, asynchronous actions
Vuex, vuex, Vue 2, state management, 状态管理, store, state, getters, mutations, actions, modules, 存储, 状态, 获取器, 变更, 动作, 模块, Vuex store, Vuex state, Vuex getters, Vuex mutations, Vuex actions, Vuex modules, Vuex plugins, centralized state, reactive state, synchronous mutations, asynchronous actions