laravelvue.jslaravel-5.3vuejs2vue-resource

Where is Vue.use(VueResource) string in Laravel project?


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?


Solution

  • 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