Home> Web Front-end> Vue.js> body text

What is vue.js plugin

藏色散人
Release: 2023-01-13 00:44:56
Original
3009 people have browsed it

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.

What is vue.js plugin

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({ // ...组件选项 })
Copy after login

To prevent multiple registrations of the same plugin: We can pass an optional object

Vue.use(MyPlugin, { someOption: true })
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!