Plugins are global JavaScript functions encapsulated in .js files that can be installed in your app by using the Vue.use global method. We have used some Vue plugins in our past examples in Chapter 4, Adding Views, Routes, and Transitions, such as vue-router and vue-meta. These plugins must be installed through the Vue.use method before the root Vue is initiated with the new statement, as seen in the following example:
// src/entry.js
import Vue from 'vue'
import Meta from 'vue-meta'
Vue.use(Meta)
new VueRouter({ ... })
You can pass options into the plugin through Vue.use to configure the plugin in this format:
Vue.use(<plugin>, <options>)
For example, we can pass the following options into the vue-meta plugin:
Vue.use(Meta, {
keyName: metaData, // default => metaInfo
refreshOnceOnNavigation: true // default => false
})
Options are optional. That means you can use the plugin itself without passing in any of them. Vue.use also can...