Plugins

This is a very early preview for the plugin API and this may change in future versions. You might want to wait for a few official plugins as reference before writing your own.

Using a Plugin

Verbose version

1
2
3
4
5
6
7
8
9
// assuming using a CommonJS build system
var vueTouch = require('vue-touch')
// use the plugin globally
Vue.use(vueTouch)

// Extended components can use plugins too!
var awesomePlugin = require('vue-awesome'),
MyComponent = Vue.extend({})
MyComponent.use(awesomePlugin)

Shorthand equivalent

1
2
// will auto require('vue-touch')
Vue.use('vue-touch')

The shorthand only works in Component, not in Browserify! Browserify uses static parsing to extract dependencies and cannot handle dynamic require().

Optional arguments

1
2
// every additional argument will be passed to the plugin
Vue.use('vue-touch', { moveTolerance: 12 })

Plugin Implementation

Note that the passed in Vue constructor could be an extended Component constructor. Assume that only Vue.require() and asset registration methods are available. Do not use Vue.config() inside plugins.

1
2
3
4
exports.install = function (Vue, options) {
// use Vue.require to access internal modules
var utils = Vue.require('utils')
}