我是国家管理的用户 这是 my store.js 文件
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);
export const store = new Vuex.Store({
state: {
loggedIn : false
},
getters: {},
mutations: {
m_logInUser: state => {
state.loggedIn = true;
}
},
actions: {
a_logInUser : ({commit}, user) => {
alert(user.e);
commit('m_logInUser');
},
a_signUpUser : ({commit}) => {
commit('m_logInUser');
}
}
});
这是我用来改变状态的组件
<template>
<div class="container">
<div class="row">
<div class="form_bg center-block">
<form @submit.prevent="a_logInUser({e: email, value:100})">
<br/>
<div class="form-group">
<input v-model="email" type="email" class="form-control" placeholder="Your Email">
</div>
<div class="align-center">
<button type="submit" class="btn btn-success center-block">Log in</button>
</div>
</form>
</div>
</div>
<script>
import { mapActions } from 'vuex'
export default{
data(){
return{
email: ' '
};
},
computed: {
...mapActions([
'a_logInUser'
])
}
}
</script>
但问题是当我按下登录按钮显示警告时显示电子邮件中输入的值我未定义
答案 0 :(得分:2)
您应该在mapActions
使用methods
,而不是computed