Randy 9 years ago
parent
commit
3378dd281a
2 changed files with 15 additions and 15 deletions
  1. 1 1
      docs/zh-cn/intro.md
  2. 14 14
      docs/zh-cn/state.md

+ 1 - 1
docs/zh-cn/intro.md

@@ -1,6 +1,6 @@
 ## 什么是 Vuex?
 
-Vuex 是 Vue.js 应用的 state 管理结构。它受启发于 [Flux](https://facebook.github.io/flux/) 和 [Redux](https://github.com/rackt/redux),但 Vuex 的设计更加符合 Vue.js 的 reactivity system
+Vuex 是 Vue.js 应用的 state 管理结构。它受启发于 [Flux](https://facebook.github.io/flux/) 和 [Redux](https://github.com/rackt/redux),但 Vuex 的设计更加符合 Vue.js 的响应系统(reactivity system)
 
 ## 我为什么需要它?
 

+ 14 - 14
docs/zh-cn/state.md

@@ -1,19 +1,19 @@
 # State
 
-### Single State Tree
+### 单状态树
 
-Vuex uses a **single state tree** - that is, this single object contains all your application level state and serves as the "single source of truth". This makes it straightforward to locate a specific piece of state, and allows us to easily take snapshots of the current app state for debugging purposes.
+Vuex 使用 **单状态树(single state tree)** —— 也就是单个对象包含整个应用的 state。这使得我们在 debugging 的过程中能直接定位相关的 state,快速地取得当前应用的 state 快照(snapshots)。
 
-The single state tree does not conflict with modularity - in later chapters we will discuss how to split your state managing logic into sub modules.
+单状态树和模块化不冲突——在往后的章节里我们会讨论如何将状态管理分离到各个子模块中。
 
-### Getting Vuex State into Vue Components
+### 在 Vue 组件中获得 Vuex State
 
-Similar to `data` objects passed to Vue instances, the `state` object, once passed into a Vuex instance, becomes reactive powered by [Vue's reactivity system](http://vuejs.org/guide/reactivity.html). This means binding Vuex state to Vue components is as simple as returning it from within a computed property:
+和 Vue 实例中的 `data` 对像一样,`state` 对象一旦进入 Vuex 实例,就会变成响应的(powered by [Vue.js 响应系统](http://vuejs.org/guide/reactivity.html))。也就是说,要将 Vuex state 和 Vue 组件联系在一起,只需要简单地将前者返回给后者的 computed 属性。
 
 ``` js
-// inside a Vue component module
+// 一个 Vue 组件模块内部
 
-// import a vuex instance
+// 引入一个 vuex 实例
 import vuex from './vuex'
 
 export default {
@@ -25,11 +25,11 @@ export default {
 }
 ```
 
-There's no need to worry about setting up and tearing down listeners, or "connecting" the component to a store. The only thing to remember is that you should **always reference state via `vuex.state.xxx` inside your computed properties**. Do not cache the reference to a piece of state outside computed properties.
+不需要建立任何监听器或者建立组件和 store 之间的联系,你唯一要记住的是,**在 computed 属性里,必须通过 `vuex.state.xxx` 引用 state**。不能在 computed 属性外部存放 state 的引用。
 
 > Flux reference: this can be roughly compared to [`mapStateToProps`](https://github.com/rackt/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options) in Redux and [getters](https://optimizely.github.io/nuclear-js/docs/04-getters.html) in NuclearJS.
 
-Why don't we just use `data` to bind to vuex state? Consider the following example:
+你会问为什么我们不直接用 `data` 去绑定 vuex state,我们看以下例子:
 
 ``` js
 export default {
@@ -41,12 +41,12 @@ export default {
 }
 ```
 
-Because the `data` function does not track any reactive dependencies, we are only getting a static reference to `vuex.state.message`. When the Vuex state is mutated later, the component has no idea that something has changed. In comparison, computed properties track all reactive dependencies when they are evaluated, so they reactively re-evaluate when the related vuex state mutates.
+因为 `data` 函数不追踪任何 reactive dependencies, 仅仅是一个对 `vuex.state.message` 的静态引用。即使之后 Vuex state 被改变,组件也无法知道它的改变。而 computed 属性不同,它在 state 改变的时候会跟踪所有 reactive dependencies。
 
-### Components Are Not Allowed to Directly Mutate State
+### 组件不允许直接改变 state
 
-Using read-only computed properties has another benefit in that it helps emphasizing the rule that **components should never directly mutate Vuex state**. Because we want every state mutation to be explicit and trackable, all vuex state mutations must be conducted inside vuex mutation handlers.
+使用只读的 computed 属性有一个好处就是,能更好的遵守 **组件永远不能直接改变 Vuex state** 的准则。由于我们希望每一个 state 都意图清晰且可被跟踪,所有的 vuex state mutations 都必须在 vuex mutation handlers 当中。
 
-To help enforce this rule, when in [Debug Mode](debug.md), if Vuex state is mutated outside of mutation handlers, Vuex will throw an error.
+为了践行这条准则,当你在 [Debug 模式](debug.md) 中在 mutation handlers 外部改变 Vuex state 时,Vuex 会抛出错误。
 
-With this rule in place, our Vue components now hold a lot less responsibility: they connect to Vuex state via read-only computed properties, and the only way for them to affect Vuex state is by calling **actions**, which in turn trigger **mutations**. They can still possess and operate on their local state if necessary, but we no longer put any data-fetching or global-state-mutating logic inside individual components.
+根据这条准则,我们的 Vue 组件处理的事情就很少了:只需要通过只读的 computed 属性和 Vuex state 建立联系,改变 state 的唯一方法是调用 **actions**. 它们照样能在必要时对 state 进行操作,但我们再也不需要在组件里做任何数据获取和 state 相关的逻辑了。