Vue.js.使用事件总线或存储哪个更好? [英] Vue.js. Which better to use event bus or storage?

查看:43
本文介绍了Vue.js.使用事件总线或存储哪个更好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have 2 components on the page. One of them is filters and other is list of results.

制作了两个组件的原因:1. 它们太大,无法在单个组件中使用2. 分开制作.我可以使用没有过滤器的列表组件.

Two components have been made in reasons: 1. They are too large to use in single component 2. Made them separately. I can use list component without filters.

现在组件通过总线事件进行通信.我的问题是:我是继续使用总线事件还是删除它并通过 vuex 存储制作?".

Now components are communicated via Bus event. And my question is: "Do I continue to use bus event or delete it and make via vuex storage?".

附言我想听听真实的 еips 和解释

P.S. I would like to hear real еips with explanations

P.S.S.请不要写你是白痴"之类的话.

P.S.S. Please don't write something like "you are idiot" and etc.

推荐答案

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

I guess it's a matter of analyzing your needs. I usually think like this:

如果是只在那里发生的简单事件,请使用总线.如果这些过滤器不是在父级中使用的,则存储它们.Vuex 已经到位,所有逻辑都已存储,为了一致性而存储.

If it's a simple event that only happens there, use the bus. If those filters are used other than in the parent, store them. Vuex is already in place and every logic is stored, store it for sake of consistency.

这篇关于Vue.js.使用事件总线或存储哪个更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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