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.
// 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)
// 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()`.
// every additional argument will be passed to the plugin
Vue.use('vue-touch', { moveTolerance: 12 })
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.
exports.install = function (Vue, options) {
// use Vue.require to access internal modules
var utils = Vue.require('utils')
}