You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Vuex 2.0 is released, but this guide only covers the migration to 1.0? Is that a typo? Also, it looks like Vuex 1.0 and 2.0 were released simultaneously. What's going on? Which one should I use and what's compatible with Vue 2.0?
They have slightly different target users however.
14
+
然而它们的目标用户稍微有所不同。
15
15
16
-
__Vuex 2.0__is a radical redesign and simplification of the API, for those who are starting new projects or want to be on the cutting edge of client-side state management. __It is not covered by this migration guide__, so you should check out [the Vuex 2.0 docs](https://vuex.vuejs.org/en/index.html) if you'd like to learn more about it.
__Vuex 1.0__is mostly backwards-compatible, so requires very few changes to upgrade. It is recommended for those with large existing codebases or who just want the smoothest possible upgrade path to Vue 2.0. This guide is dedicated to facilitating that process, but only includes migration notes. For the complete usage guide, see [the Vuex 1.0 docs](https://github.com/vuejs/vuex/tree/1.0/docs/en).
`store.watch`now only accept functions. So for example, you would have to replace:
24
+
`store.watch`现在只接受函数。因此,下面例子你需要替换:
25
25
26
26
```js
27
27
store.watch('user.notifications', callback)
28
28
```
29
29
30
-
with:
30
+
为:
31
31
32
32
```js
33
33
store.watch(
34
-
//When the returned result changes...
34
+
//当返回结果改变...
35
35
function (state) {
36
36
returnstate.user.notifications
37
37
},
38
-
//Run this callback
38
+
//执行回调函数
39
39
callback
40
40
)
41
41
```
42
42
43
-
This gives you more complete control over the reactive properties you'd like to watch.
43
+
这帮助你更加完善的控制那些需要监听的响应式属性。
44
44
45
45
{% raw %}
46
46
<divclass="upgrade-path">
47
-
<h4>Upgrade Path</h4>
48
-
<p>Run the <ahref="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of <code>store.watch</code> with a string as the first argument.</p>
The store instance no longer exposes the event emitter interface (`on`, `off`, `emit`). If you were previously using the store as a global event bus, [see this section](http://vuejs.org/guide/migration.html#dispatch-and-broadcast-deprecated) for migration instructions.
54
+
store 实例不再暴露事件触发器(event emitter)接口(`on`, `off`, `emit`)。如果你之前使用 store 作为全局的 event bus,迁移说明相关内容请查阅[此章节](http://vuejs.org/guide/migration.html#dispatch-and-broadcast-deprecated)。
55
55
56
-
Instead of using this interface to watch events emitted by the store itself (e.g. `store.on('mutation', callback)`), a new method `store.subscribe` is introduced. Typical usage inside a plugin would be:
56
+
为了替换正在使用观察 store 自身触发事件的这些接口,(例如:`store.on('mutation', callback)`),我们引入新的方法 `store.subscribe`。在插件中的典型使用方式如下:
57
57
58
58
```js
59
59
varmyPlugin=store=> {
@@ -64,18 +64,18 @@ var myPlugin = store => {
64
64
65
65
```
66
66
67
-
See example [the plugins docs](https://github.com/vuejs/vuex/blob/1.0/docs/en/plugins.md) for more info.
<p>Run the <ahref="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of <code>store.on</code>, <code>store.off</code>, and <code>store.emit</code>.</p>
Middlewares are replaced by plugins. A plugin is simply a function that receives the store as the only argument, and can listen to the mutation event on the store:
78
+
中间件被替换为插件。插件是接收 store 作为仅有参数的基本函数,能够监听 store 中的 mutation 事件:
79
79
80
80
```js
81
81
constmyPlugins=store=> {
@@ -85,11 +85,11 @@ const myPlugins = store => {
85
85
}
86
86
```
87
87
88
-
For more details, see [the plugins docs](https://github.com/vuejs/vuex/blob/1.0/docs/en/plugins.md).
<p>Run the <ahref="https://github.com/vuejs/vue-migration-helper">migration helper</a> on your codebase to find examples of the <code>middlewares</code> option on a store.</p>
0 commit comments