0. Development of plug-ins
I jump development plug-in web page Especially the rain creek teach you write plug-ins link: www.bilibili.com/video/BV1d4…
1. What is a plug-in?
Plugins are usually used to add global functionality to a Vue. There is no strict limit on the function range of plug-ins. Plug-ins commonly used are as follows:
- View component library,
Element UI
.Vant
- A functional module, for example
vue-router
- Add global methods or
property
. Such as:vue-custom-element
Etc.
2. Features of plug-ins
It can be used globally on all pages and components after an entry file is declared by vue. use
3. Write your own plugin
The vue.js plug-in exposes an install method. The first argument to this method is the Vue constructor, and the second argument is an optional option object
Vue calls install. In fact, the plug-in is an object with a fixed install attribute
const myPlugin = {
install: function (vue, options) {
// Make anything}}// Use plugins
Vue.use(myPlugin)
Copy the code
Define global component Vue.component(component name, import object):cn.vuejs.org/v2/api/#Vue…
The use of the plug-in is to put the above declaration into the install method and call it using. You can also define some global filters/directives/mixins