Extending Vue
Extend with Mixins
Mixins are a flexible way to distribute reusable functionalities for Vue components. You can write a mixin just like a normal Vue component option object:
1 | // mixin.js |
1 | // test.js |
Extend with Plugins
Plugins usually adds global-level functionality to Vue.
Writing a Plugin
There are typically several types of plugins you can write:
- Add one or more global methods. e.g. vue-element
- Add one or more global assets: directives/filters/transitions etc. e.g. vue-touch
- Add some Vue instance methods by attaching them to Vue.prototype. The convention here is Vue instance methods should be prefixed with
$
, so that they don’t conflict with user data and methods.
1 | exports.install = function (Vue, options) { |
Using a Plugin
Assuming using a CommonJS build system:
1 | var vueTouch = require('vue-touch') |
You can also pass in additional options to the plugin:
1 | Vue.use('my-plugin', { |
Existing Tools
- vue-devtools: A Chrome devtools extension for debugging Vue.js applications.
- vue-touch: Add touch-gesture directives using Hammer.js.
- vue-element: Register Custom Elements with Vue.js.
- List of User Contributed Tools
Caught a mistake or want to contribute to the documentation? Fork this site on Github!