File tree 1 file changed +41
-0
lines changed
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,47 @@ vuex 是什么,怎么搭,以及 要有用什么角度来理解这个插件
49
49
> 3 . actions (动作),用户在 视图 上的输入引起状态的更改的可能方式。
50
50
51
51
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
+
52
93
> ### Vuex 观念 demo
53
94
> - demo https://bhnddowinf.github.io/bhnddowinf/vuejs2demo/vuex01.html
54
95
> - 源码 https://github.com/bhnddowinf/vuejs2-learn/blob/master/my-project/src/vuex-demo/v01_app.js
You can’t perform that action at this time.
0 commit comments