【问题标题】:Vue.js. Which better to use event bus or storage?Vue.js。使用事件总线或存储哪个更好?
【发布时间】:2018-06-05 08:10:45
【问题描述】:

我在页面上有 2 个组件。其中一个是过滤器,另一个是结果列表。

制作的原因有两个: 1.它们太大而无法在单个组件中使用 2. 分别制作。我可以使用不带过滤器的列表组件。

现在组件通过Bus event 进行通信。我的问题是:“我是继续使用总线事件还是将其删除并通过 vuex 存储制作?”。

附:我想听听真正的 еips 和解释

附言请不要写“你是白痴”之类的东西。

【问题讨论】:

  • 您要对两个组件之间发送的数据进行操作吗?或者它只是一种动作反应类型的事件?
  • vuejs.org/v2/style-guide/… Vuex should be preferred for global state management, instead of this.$root or a global event bus. Managing state on this.$root and/or using a global event bus can be convenient for very simple cases, but are not appropriate for most applications. Vuex offers not only a central place to manage state, but also tools for organizing, tracking, and debugging state changes.
  • @ErikTerwan 动作反应类型的事件
  • @JacobGoh 已阅读文档。但是我在阅读 vuex 之前编写了我的代码。这就是为什么我问我的问题,要知道我是否需要重写我的代码或者性能没有任何差异。
  • 性能方面,我不知道哪个更快,但除非您的应用处理大量数据,否则不会有明显差异。

标签: javascript vue.js


【解决方案1】:

我想这是分析您的需求的问题。 我通常是这样想的:

如果只是在那里发生的简单事件,请使用公共汽车。 如果这些过滤器在父级以外的地方使用,请将它们存储起来。 Vuex 已经就位,每个逻辑都存储了,为了一致性而存储。

【讨论】:

    猜你喜欢
    • 2020-12-07
    • 1970-01-01
    • 2017-07-14
    • 2016-10-30
    • 2010-11-15
    • 2018-04-29
    • 2022-11-04
    • 2011-09-22
    • 1970-01-01
    相关资源
    最近更新 更多