4

In many tutorials about VueJS I see this example:

import VueResource from 'vue-resource';
Vue.use(VueResource);

But in newly created Laravel 5.3 project I found only this code (bootstrap.js file):

window.Vue = require('vue');
require('vue-resource')

And found no "use" directive for vue-resource, but AJAX queries like this.$http.get() still work well. So, how Vue instance can use vue-resource?

Saurabh
  • 71,488
  • 40
  • 181
  • 244
brunen9
  • 112
  • 9

1 Answers1

3

vue-router doesn't require use if Vue is declared globally. From the official docs:

Some plugins provided by Vue.js official plugins such as vue-router automatically calls Vue.use() if Vue is available as a global variable. However in a module environment such as CommonJS, you always need to call Vue.use() explicitly.

In laravel, you will see that Vue is declared globally by attaching it to window like so:

window.Vue = require('vue');

So the use is not required.

source: https://v2.vuejs.org/v2/guide/plugins.html#Using-a-Plugin

tony19
  • 125,647
  • 18
  • 229
  • 307
craig_h
  • 31,871
  • 6
  • 59
  • 68
  • If I understand the concept behind Vue framework clearly... When I don't know if it is official plugin or not - I still can use Vue.use('some_plugin') and Vue will automatically prevents me from using the same plugin more than once, right? – brunen9 Jan 04 '17 at 16:13