首页 > 解决方案 > 对事件总线的性能影响

问题描述

在我们的 Vue 应用程序中,我们使用多个事件总线来接收/发送事件。

方法 A:单独的事件总线

有些组件只需要处理一个通道(我们只需要导入我们需要的总线)。

import Vue from 'vue'
export const CanvasBus = new Vue()
export const NotificationBus = new Vue()
export const FileBus = new Vue()
export const UIBus = new Vue()

方法 B:一个事件总线

我们可以只有一个事件总线来处理所有事件,但这意味着所有事件都被发送到所有侦听器。

import Vue from 'vue'
export const EventBus = new Vue()

使用这种方法,每个事件都会有一个额外的参数type(可能是“Canvas”、“UI”、“File”等)。

问题: 是否存在某种方式的性能影响,例如必须加载多个 Vue 实例,或者不用担心,它只是归结为组织偏好?

标签: vue.js

解决方案


推荐阅读