Skip to content

Commit e3e5495

Browse files
committed
U
1 parent 1a15c6b commit e3e5495

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

vuex-learn.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,47 @@ vuex 是什么,怎么搭,以及 要有用什么角度来理解这个插件
4949
> 3. actions (动作),用户在 视图 上的输入引起状态的更改的可能方式。
5050
5151

52+
# 问题: vuex,action ,mutations 做什么用的?
53+
54+
55+
## (1) state
56+
57+
- 中文翻译成「状态」,建议尽量用 state 这个单字来阅读 vuex 文檔,不然你脑海一直出现状态状态状态,反而会卡死。
58+
59+
- 整个 vuex 是一颗 独立的 state tree,规定:只允许 mutation ,才能改变 state
60+
61+
```js
62+
const state = {
63+
count: 0
64+
}
65+
```
66+
67+
## (2) mutation
68+
69+
(2-1) 更改 Vuex 的 store 中的 state 的唯一方法是提交 mutation。
70+
71+
(2-2) mutation,会与插件 devtools 协作,当 mutation 有变化时, 就做 state 的纪录,来协助开发者 debug,所以这里的代码要求同步,以便插件来调试。
72+
73+
74+
(2-3) 来源:https://vuex.vuejs.org/zh-cn/mutations.html
75+
76+
77+
## (3) Action 类似于 mutation,不同在于:
78+
79+
(3-1) Action 提交的是 mutation(让 mutation 处理插件的调试工作 ),而不是直接变更 state 。
80+
81+
(3-2) Action 可以包含任意异步操作。
82+
83+
(3-3) 来源:https://vuex.vuejs.org/zh-cn/actions.html
84+
85+
小凡:mutation 的工作,要把 state 作响应式的处理,还要发讯息给devtool, 还要去操作 state , 有多重工作。
86+
87+
88+
89+
90+
91+
92+
5293
> ### Vuex 观念 demo
5394
> - demo https://bhnddowinf.github.io/bhnddowinf/vuejs2demo/vuex01.html
5495
> - 源码 https://github.com/bhnddowinf/vuejs2-learn/blob/master/my-project/src/vuex-demo/v01_app.js

0 commit comments

Comments
 (0)