Vuex 和事件总线有什么区别? [英] What is the difference between Vuex and Event Bus?

查看:45
本文介绍了Vuex 和事件总线有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解组件之间的通信原理,出现了一个疑问:Vue 事件总线策略和 Vuex 处理组件通信的主要区别是什么?除此之外,什么时候使用它们的最佳时间以及在同一个项目中使用两者的最佳实践是什么?

I am trying to understand the principle of communication between components and a doubt has arisen: what is the main difference between Vue event bus strategy and Vuex to deal with components communication? Besides that, when is the best time of use of each one and what is the best practice to use both in the same project?

推荐答案

vue 事件总线是 Vue 的一个单独实例.Vuex 是一个(基于flux)状态管理库,与当前的Vue 实例集成,并添加了很多功能.

the vue event bus is a separate instance of Vue. Vuex is a (flux based) state managment library that integrates with the current instance of Vue, and adds a lot of functionality.

如果您可以使用 Vuex 解决问题,我认为您根本不应该使用事件总线.

I think you shouldn't be using the event bus at all if you can solve an issue using Vuex.

Vuex 实现了通量模式,该模式允许组件根据存储突变轻松订阅更改.

Vuex implements the flux pattern that allows components to easily subscribe to changes based on store mutations.

img src: https://medium.com/@cabot_solutions/flux-the-react-js-application-architecture-a-comprehensive-study-fd2585d06483

这篇关于Vuex 和事件总线有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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