Vue.useとは
Pluginを使用するためのメソッド
Vue.useはPluginを使用するために呼ばれます。
// calls `MyPlugin.install(Vue)`
Vue.use(MyPlugin)
new Vue({
//... options
})
公式ドキュメントにはPluginを使用するためにはnew Vue()
を呼び出す前にVue.useで呼び出す必要があるとの記載がありました。
Use plugins by calling the Vue.use() global method. This has to be done before you start your app by calling new Vue()
引用:「Plugins」
https://vuejs.org/v2/guide/plugins.html
Vue.useを複数回呼び出した時の挙動
同一Pluginの読み込みは1度だけになる
globalでVue.useを使ってPluginを読み込んでいるのにさらに個別ページでVue.useでPluginを読み込む処理を書いてしまっていた場合でも、Vue.js側で同一のPluginの読み込みは1度だけになるように調整してくれます。
Vue.use automatically prevents you from using the same plugin more than once, so calling it multiple times on the same plugin will install the plugin only once.
引用:「Plugins」
https://vuejs.org/v2/guide/plugins.html
Plugin(特に公式のPlugin, vue-router ...etc)によっては内部でVue.useを呼んでくれるので仮に重複してVue.useを書いてしまっても何度もPluginを読み込みしてしまうということは発生しないです。
参考文献: