Bus Global de Eventos en Vue

Vue 3 elimina el bus de eventos integrado. Aprende a usar mitt como bus global ligero y, ante estados complejos, Pinia. Guía de buenas prácticas y soluciones de desarrollo en Q2BSTUDIO.

24 sept 2025 • 2 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Comunicación entre componentes en aplicaciones Vue puede complicarse cuando existen muchos componentes anidados; enviar una señal de un componente hijo a otro no relacionado sin propagar props o elevar demasiado el estado es un reto común.

En Vue 2 era habitual usar un bus global de eventos basado en los métodos $on, $emit y $off de las instancias de Vue, pero en Vue 3 esa API fue eliminada como parte de los cambios incompatibles. El motivo fue favorecer patrones de gestión de estado más predecibles y reducir dependencias ocultas entre componentes, por eso hoy conviene conocer alternativas modernas.

Una alternativa ligera y práctica es mitt, una pequeña librería de emisor de eventos que funciona perfectamente como bus global en Vue 3. Flujo recomendado: instalar mitt con npm install mitt; crear un archivo eventBus.js donde se inicializa un emisor con mitt y se exporta para usarlo en toda la aplicación; desde un componente emitir eventos con emitter.emit indicando el nombre del evento y un payload; en componentes que escuchan suscribirse con emitter.on durante el montaje y limpiar con emitter.off en el desmontado o usando onUnmounted para evitar fugas de memoria.

Ejemplo conceptual de uso: desde Componente A llamar a emitter.emit con un evento denominado custom-event y un objeto con datos; en Componente B registrar una función de manejo con emitter.on para custom-event durante onMounted y eliminarla en onUnmounted. Este patrón mantiene los componentes desacoplados y es ideal para comunicación ligera o prototipos rápidos.

Para aplicaciones más complejas o con mucho estado compartido es preferible usar una solución estructurada como Pinia, que ofrece una gestión de estado escalable y facilita trazabilidad y pruebas. En general: usar bus global para casos puntuales y comunicación simple; no abusar de eventos globales para no dificultar el depurado; preferir Pinia cuando exista estado compartido significativo; limpiar siempre los listeners para evitar memory leaks.

En Q2BSTUDIO desarrollamos soluciones profesionales a medida que incluyen integración de frontends modernos como Vue 3 junto con arquitecturas de backend robustas y servicios gestionados en la nube. Si necesita una aplicación a medida o software a medida podemos diseñar la mejor estrategia de comunicación entre componentes, elegir herramientas como mitt o Pinia y aplicar buenas prácticas de ingeniería.

Además ofrecemos servicios de inteligencia artificial, agentes IA y soluciones de ia para empresas, junto con servicios de ciberseguridad y pentesting, y despliegues en servicios cloud aws y azure. Podemos también integrar soluciones de servicios inteligencia de negocio y power bi para explotación de datos. Conoce nuestras capacidades en inteligencia artificial en Nuestros servicios de Inteligencia Artificial.

Resumen: Vue 3 eliminó el bus de eventos integrado, pero con librerías como mitt se puede recrear un bus global ligero y efectivo. Para proyectos que crezcan en complejidad, adoptar Pinia y patrones de gestión de estado es la opción más mantenible. En Q2BSTUDIO unimos experiencia en desarrollo de aplicaciones a medida, inteligencia artificial, ciberseguridad y servicios cloud para entregar soluciones completas y seguras.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat