Plugins
Vue.js plugins are a way to add custom functionality to Vue.js globally. Good candidates for plugins are core to the application and used widely. Classic examples of plugin candidates are translation/internationalization libraries (such as i18n-next
) and HTTP clients (such as the axios
, fetch
, and GraphQL
clients). The plugin initializer has access to the Vue
instance, so it can be a good way to wrap global directive, mixin, component, and filter definitions.
Plugins can inject functionality by registering directives and filters. They can also add global
and instance
Vue.js methods, as well as defining global component mixins.
A Vue.js plugin is an object that exposes an install
method. The install
function is called with Vue
and options
:
const plugin = { install(Vue, options) {} }
Within the install
method, we can register directives, filters, and mixins and add global and instance properties and methods:
const plugin = { install...