带有params但得到null params值的vuex调度操作



我正试图在我的vuex中创建操作,该操作具有goLogin的方法,参数为电子邮件和密码的对象,在这种情况下,我使用的是Nuxt,当我尝试在组件中使用fetch时,调度参数配合良好,但当我尝试将其作为@click的方法移动时,调度参数为空以为操作方法中的控制台日志,它不是空的,但当它到达后端API时,后端API将其读取为空

以下是我的行动:店内/login.js

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);
})
}
}

登录服务是从实例axios获得的,它就像这个

tryLogin(obj) {
// I console.log the obj here, it was not null
return goAxios.get("/login", {
data : obj,
})
}

在我的组件方法中单击登录

async tryLoginFromComponent() {
await this.$store.dispatch("login/goLogin",{
"email": "test@gmail.com",
"password": "12345678",
})
},

当我单击login时,tryLoginFromComponent的方法运行,它将在store/login.js中运行但那个params的obj在后端为null,我认为console.log不是,

我上面做的是不是有什么问题??我试着搜索了一整天,但找不到适合我的工作,我希望这里的每个人都能节省我的时间

您不必异步调用tryLoginFromComponent,因为actions已经是异步的了。也许有问题。

tryLoginFromComponent() {
this.$store.dispatch("goLogin",{
email: "test@gmail.com",
password: "12345678",
})
},

无需在此处将电子邮件和密码置于双引号中。这是一个对象,而不是JSON键值对。试试看。

最新更新