Skip to content

Commit fb18157

Browse files
committed
U
1 parent ac1d747 commit fb18157

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

vuex-learn.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const mutations = {
100100
> 来源:https://vuex.vuejs.org/zh-cn/actions.html
101101
102102
```js
103+
// 建议把此区当做事件注册来看, action 也不是马上就执行,只向 mutation 做 commit 的指令。
103104

104105
const actions = {
105106
increment: ({
@@ -116,6 +117,8 @@ const actions = {
116117
commit('increment')
117118
}
118119
},
120+
121+
// 如果 action 有异步的要求时,可以参考下列的写法,对 mutation 提出 commit 。
119122
incrementAsync({
120123
commit
121124
}) {
@@ -129,6 +132,20 @@ const actions = {
129132

130133
```
131134
135+
## 观念讲解 : vuex,action ,mutations 做什么用的?(4) getters
136+
137+
> 请当做 计算属性来写,所有的 getter, 接收 完整的state树,做第一个参数
138+
139+
``` js
140+
const getters = {
141+
evenOrOdd: state => state.count % 2 === 0 ? '偶数' : '奇数'
142+
}
143+
144+
```
145+
146+
147+
148+
132149
133150
134151

0 commit comments

Comments
 (0)