我应该将所有数据存储在 vuex 状态吗 [英] Should I store all the data in vuex state

查看:51
本文介绍了我应该将所有数据存储在 vuex 状态吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 Vuex,是否意味着将所有数据都存储在 vuex/state 中更好?我有点困惑,我从 API 获得的一些数据(例如 UserDetail),我不需要它在组件中共享,或者我可以轻松地将它作为道具传递.我应该在 Vuex/State 中保留那种数据吗?为什么不通过Promise获取数据或者只使用Vuex/Action/Promise?

If I use Vuex, is that means it's better to store every data in the vuex/state? I have a little confused, some data I get from API (for example UserDetail), I don't need it be shared in components or I counld easily pass it as props. Should I keep that kind of data in Vuex/State? Why not get the data by Promise or only use Vuex/Action/Promise?

推荐答案

数据应尽可能本地化.这是有助于降低复杂性的一般原则.Vuex 应该处理需要在不密切相关的组件之间共享的数据.

Data should be kept as local as possible. That's a general principle that helps reduce complexity. Vuex should handle data that needs to be shared among not-closely-related components.

这篇关于我应该将所有数据存储在 vuex 状态吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆