首页 > 解决方案 > 更好的 nuxt vuex 工作流程?

问题描述

所以......我正在用 Nuxt 开发一个应用程序

我的前端有以下结构,但我不知道这是否是正确的方法,

基本上我正在调度 VueX 动作

component.vue

await this.$store.dispatch('auth/login', {email, password})

在 auth/login vuex 模块中,我这样做:

store/auth.js

    async login({commit}, {email, password}){
        try {
            let user = await this.$repositories.auth.login({email, password})
            await commit('SET_AUTH_INSTANCE', user)
            await commit('SET_AUTH_TOKEN', user.token)
        } catch (error) {

        }
    },

我到底在问什么...

我应该改变业务逻辑吗?我是否应该在 vue 组件中调用存储库 API 并仅使用有效负载分派操作以便我可以提交它们?

例如:

component.vue

let user = await this.$repositories.auth.login({email, password})
await this.$store.dispatch('auth/login', user)

store/auth.js

    async login({commit}, user){
        try {
            await commit('SET_AUTH_INSTANCE', user)
            await commit('SET_AUTH_TOKEN', user.token)
        } catch (error) {

        }
    },

标签: vue.jsvuexnuxt.js

解决方案


推荐阅读