Home >Web Front-end >Vue.js >What is vue.js plugin
vue.js plug-in is a functional module used to enhance the technology stack. Its target is Vue; plug-ins also enhance and supplement the functions of Vue; plug-ins are usually used to add global functions to Vue, but the plug-in The functional scope is not strictly limited.
The operating environment of this article: windows10 system, vue2.9 version, thinkpad t480 computer.
vue plug-in
Plugin (Plugin) is a functional module used to enhance your technology stack. Its target is Vue itself. (Plug-ins are enhancements and supplements to Vue’s functions)
Official explanation
Plug-ins are usually used to add global functions to Vue. There are no strict restrictions on the functional scope of plug-ins - generally there are the following types:
Add global methods or properties. For example: vue-custom-element
Add global resources: directives/filters/transitions, etc. For example, vue-touch
adds some component options through global mixing. For example, vue-router
adds Vue instance methods by adding them to Vue.prototype.
A library that provides its own API while providing one or more of the functions mentioned above. For example, vue-router
How to use the plug-in
Use the plug-in through the global method Vue.use(). It needs to be completed before you call new Vue() to start the application:
// 调用 `MyPlugin.install(Vue)` Vue.use(MyPlugin) new Vue({ // ...组件选项 })
To prevent multiple registrations of the same plugin: We can pass an optional object
Vue.use(MyPlugin, { someOption: true })
Vue.use will automatically Prevent multiple registrations of the same plug-in, in which case the plug-in will only be registered once even if called multiple times.
Note:
Some plug-ins officially provided by Vue.js (such as vue-router) will automatically call Vue.use() when detecting that Vue is an accessible global variable. However in a module environment like CommonJS you should always call Vue.use() explicitly:
// 用 Browserify 或 webpack 提供的 CommonJS 模块环境时 var Vue = require('vue') var VueRouter = require('vue-router') // 不要忘了调用此方法 Vue.use(VueRouter)
The above is the detailed content of What is vue.js plugin. For more information, please follow other related articles on the PHP Chinese website!