A real-world example – a modals plugin
We have seen multiple approaches for sharing data and functionality within a project. Plugins are a design pattern for sharing functionality between projects and at the same time augmenting a system’s capabilities. Vue 3 provides a very simple interface to create plugins and attach them to our application instance. Any object that exposes an install()
method or a function that accepts the same parameters can become a plugin. A plugin can do the following:
- Register global components and directives
- Register an injectable resource at the application level
- Create and attach new properties or methods to the application
In this section, we will create a plugin that implements modal dialogs as global components. We will use dependency injection to provide them as a resource and leverage Vue’s reactivity to manage them through promises.
Setting up our development project
Follow the instructions in Chapter...