laravel - Laravel 项目中的 Vue.use(VueResource) 字符串在哪里?

标签 laravel vue.js laravel-5.3 vuejs2 vue-resource

在许多关于 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/

相关文章:

laravel - Webpack 监视脚本在几次成功编译后抛出错误。Laravel Homestead

javascript - 如何在vuex的actions.js中使用router?

php - 如何从公用文件夹中获取图像文件作为 Laravel 中的响应?

php - laravel undefined variable 保护

php - 如何从对象获取属性(PHP)

php - 如何在一个 View 中从两个表中获取多列数据

通过 SSL https 连接的 Laravel IO Socket 和 redis

javascript - CORS 策略 : Response to preflight request doesn't pass access control check

javascript - 正在为未受影响的其他组件触发 Vue 指令

eloquent - Vue 2 Laravel 5.3 Eloquent 无法从对象检索数据