Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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?

share|improve this question
up vote 3 down vote accepted

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://vuejs.org/v2/guide/plugins.html#Using-a-Plugin

share|improve this answer
    
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? – Павел Мирончик Jan 4 at 16:13
    
Yes, that's right! – craig_h Jan 4 at 16:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.