在许多关于 VueJS 的教程中我看到了这个例子:
import VueResource from 'vue-resource';
Vue.use(VueResource);
但是在新创建的 Laravel 5.3 项目中我发现只有这段代码(bootstrap.js 文件):
window.Vue = require('vue');
require('vue-resource')
并没有发现 vue-resource 的“use”指令,但是像这样的 AJAX 查询。$http.get() 仍然可以正常工作。那么,Vue实例如何使用vue-resource呢?
最佳答案
vue-router
不需要 use
如果 Vue
是全局声明的。来自官方文档:
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.
在 laravel 中,你会看到 Vue
是通过将它附加到 window
来全局声明的,如下所示:
window.Vue = require('vue');
因此不需要使用
。
来源:https://v2.vuejs.org/v2/guide/plugins.html#Using-a-Plugin
关于laravel - Laravel 项目中的 Vue.use(VueResource) 字符串在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41465453/