我正在尝试在vuex中创建动作,该动作具有方法goLogin
,其参数为对象[[电子邮件和密码,在这种情况下,当我尝试使用时,我正在使用Nuxt在我的组件中,dispatch可以很好地与params一起使用,但是当我尝试将其作为@ click的方法移动时,dispatch params是null以为我在action方法内进行了控制台日志记录,它不是null,但是当它命中后端API时,后端API会将其读取为null
export const actions = {
goLogin({ commit }, obj) {
// I console.log the obj here, it was not null
return LoginService.tryLogin(obj).then((res) => {
commit("IS_LOGIN", res.data);
}).catch(e => {
commit("IS_LOGIN", e.response.data);
})
}
}
LoginService是从实例axios获得的,就像这样
tryLogin(obj) { // I console.log the obj here, it was not null return goAxios.get("/login", { data : obj, }) }
在我的@click登录组件方法中>
async tryLoginFromComponent() { await this.$store.dispatch("login/goLogin",{ "email": "[email protected]", "password": "12345678", }) },
当我单击登录时,tryLoginFromComponent
的方法运行,并且在store / login.js中生效但是该参数的obj在后端为空,以为我console.log不是,我在上面做错了吗?我整日都在尝试搜索,但找不到适合我的工作,希望这里的每个人都可以节省我的时间。
[我正在尝试在vuex中创建动作,该动作具有方法goLogin,其参数为电子邮件和密码的对象,在这种情况下,当我尝试在组件中使用fetch时,我正在使用Nuxt ...] >
tryLoginFromComponent
,因为actions
已经异步。也许有问题。 tryLoginFromComponent() {
this.$store.dispatch("goLogin",{
email: "[email protected]",
password: "12345678",
})
},