"" Click here to enter the basis of a statement calling the article ""
transfer
<div><input type="button" @click="$store.dispatch('listMore')" value="加载更多"></div>
statement:
new vuex.Store({
actions:{
listMore(context){ //它其实会默认传递一个参数,这里面有关于所有 vuex 的操作方法
console.log(context)
}
}
})
We can modify the value of the state's method by which to call mutations
new vuex.Store({
actions:{
listMore(context){ //它其实会默认传递一个参数,这里面有关于所有 vuex 的操作方法
context.commit("ZHANG_SAN");
}
}
})
Also may be acquired by the state values for the state
new vuex.Store({
actions:{
listMore(context){ //它其实会默认传递一个参数,这里面有关于所有 vuex 的操作方法
console.log(context.state.zhangsan);
}
}
})
In this case, we can deconstruct the assignment, will simplify the code, only we use to
new vuex.Store({
actions:{
listMore({commit,state,dispatch}){ //顺序不分先后,都可以使用
commit("ZHANG_SAN"); //这样我们就省去了 context
console.log(state.zhangsan);
}
}
})