简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM