vue.js - 更好的 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) {
}
},
解决方案
推荐阅读
- powershell - Powershell cmdlet 参数定义包含参数名称以 $ 开头创建默认行为更改
- php - 如何从会话中获取以特定键开头的所有值
- delphi - 如何允许在 TDBLookupComboBox 中选择 NULL 值?
- r - 每次出现给定值时如何在 R 中创建新列?
- jenkins - JMeter:通过 CMD 运行测试时,errorlevel = -1073741819
- bash - Shell Script:变量assinment以奇怪的方式工作
- docker - 子目录网站 CMS 的 NGINX 配置不会删除 /index.php/
- vue.js - 当我在 vue.js 中使用退格键时,输入没有完全清除
- rabbitmq - 启动 RabbitMQ 代理失败
- css - IE 加载不完整的资产(Vue Javascripts、样式表)