首先,有 user.js,这是其中一个模块store.js
const state = {
isLogin: false
}
const mutations = {
login(state, userid){
state.userid = userid;
}
}
export default {
state,
mutations
}
Run Code Online (Sandbox Code Playgroud)
使用Vue-router,我创建了一个App Component,然后导入store.js.
然后是组件login.vue.以下是代码的一部分:
<script>
export default {
vuex: {
actions: {
login // this action changes the state of
// isLogin by dispatch `login` mutation
}
},
methods: {
btnClick(){
// here calls the login action
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
我注意到该方法btnClick可以在这个组件中工作.它确实改变了store.state.user.isLogin.
但这是另一个a.vue听取 …