Abstract
As a Vue.js application grows, the need to pass data and events between parent and child components becomes harder to arrange, especially when components in different parts of the application need to communicate. The result can be components whose own functionality is overtaken by the need to pass on props for their descendants and relay events to their antecedents. In this chapter, I describe an alternative approach, known as dependency injection, which allows components to communicate without being tightly coupled to one another. I show you the different ways in which dependency injection can be used and demonstrate how it frees up the structure of an application. I also show you how to use an event bus, which combines dependency injection with the ability to register interest in custom events programmatically, allowing a component to send a custom event to any interested receiver, rather than just its parent. Table 18-1 puts dependency injection and event buses in context.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2018 Adam Freeman
About this chapter
Cite this chapter
Freeman, A. (2018). Loosely Coupled Components. In: Pro Vue.js 2. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-3805-9_18
Download citation
DOI: https://doi.org/10.1007/978-1-4842-3805-9_18
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-3804-2
Online ISBN: 978-1-4842-3805-9
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)