vue中的mutations方法中第一个参数
mutations方法默认接受两个参数,第一个参数是state,
这个state指向store的state,并且state不能结构
actions方法的第一个参数是context,默认可以结构
actions方法的context
context就相当于state的父亲,上一级,包含着state中的所有属性
context:{
state, 等同于store.
s
t
a
t
e
,
若
在
模
块
中
则
为
局
部
状
态
r
o
o
t
S
t
a
t
e
,
等
同
于
s
t
o
r
e
.
state,若在模块中则为局部状态 rootState, 等同于store.
state,若在模块中则为局部状态rootState,等同于store.state,只存在模块中
commit, 等同于store.
c
o
m
m
i
t
d
i
s
p
a
t
c
h
,
等
同
于
s
t
o
r
e
.
commit dispatch, 等同于store.
commitdispatch,等同于store.dispatch
getters 等同于store.$getters
}
常规写法调用的时候会使用context.commit,但更多的是使用es6的变量解构赋值,也就是直接在参数的
位置写自己想要的属性,如:{commit}。