- Impara
-
Ecosistema
Aiuto
Tooling
Librerie Core
Novità
Risorse
- Team
- Supporta Vue
- Traduzioni
Guide
Essenziale
- Installation
- Introduction
- The Vue Instance
- Template Syntax
- Computed Properties and Watchers
- Class and Style Bindings
- Conditional Rendering
- List Rendering
- Event Handling
- Form Input Bindings
- Components
Animazioni e transizioni
- Enter/Leave & List Transitions
- State Transitions
Riusabilità e Composizione
- Mixins
- Custom Directives
- Render Functions & JSX
- Plugins
- Filters
Tooling
- Production Deployment
- Single File Components
- Unit Testing
- TypeScript Support
Scaling Up
- Routing
- State Management
- Server-Side Rendering
Internals
- Reactivity in Depth
Migrazioni
- Migration from Vue 1.x
- Migration from Vue Router 0.7.x
- Migration from Vuex 0.6.x to 1.0
Meta
- Comparison with Other Frameworks
- Join the Vue.js Community!
- Meet the Team
Plugins
Writing a Plugin
Plugins usually add global-level functionality to Vue. There is no strictly defined scope for a plugin - there are typically several types of plugins you can write:
Add some global methods or properties. e.g. vue-custom-element
Add one or more global assets: directives/filters/transitions etc. e.g. vue-touch
Add some component options by global mixin. e.g. vue-router
Add some Vue instance methods by attaching them to Vue.prototype.
A library that provides an API of its own, while at the same time injecting some combination of the above. e.g. vue-router
A Vue.js plugin should expose an install
method. The method will be called with the Vue
constructor as the first argument, along with possible options:
MyPlugin.install = function (Vue, options) { |
Using a Plugin
Use plugins by calling the Vue.use()
global method:
// calls `MyPlugin.install(Vue)` |
You can optionally pass in some options:
Vue.use(MyPlugin, { someOption: true }) |
Vue.use
automatically prevents you from using the same plugin more than once, so calling it multiple times on the same plugin will install the plugin only once.
Some plugins provided by Vue.js official plugins such as vue-router
automatically calls Vue.use()
if Vue
is available as a global variable. However in a module environment such as CommonJS, you always need to call Vue.use()
explicitly:
// When using CommonJS via Browserify or Webpack |
Checkout awesome-vue for a huge collection of community-contributed plugins and libraries.