-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[vue] 你有用过事件总线(EventBus)吗?说说你的理解 #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
vue
vue
Comments
也是组件传值的一种方式(例如兄弟组件) |
我理解:事件总线是事件通知的总线,不应该滥用事件总线来进行传值。 其他组件进行监听时候实际上只关注特定对象的特定动作。 |
就是一个vue实例,利用了vue的$on、$off、$emit方法 不过在vue3中这些方法被移除了。如果还要使用,需要利用 mitt插件 |
在Vue中,事件总线是一种用于组件间通信的机制,允许不同组件之间进行事件的发布和订阅。 事件总线本质上是一个中央事件管理器,充当了组件之间的中介。它提供了一种简单而强大的方式,使得组件能够进行解耦,通过事件的方式进行通信,而不需要直接引用和依赖其他组件。 使用事件总线可以有效地解决跨组件通信的问题,特别是当组件层级较深或组件之间没有直接父子关系时。它可以减少组件之间的耦合性,提高代码的可维护性和可重用性。 示例
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[vue] 你有用过事件总线(EventBus)吗?说说你的理解
The text was updated successfully, but these errors were encountered: