Well i am playing with the new laravel 5.3 and vue.js and i want to do a GET call to some users i have in my DB

Im using components btw.

这是我的app.js

require('./bootstrap');

Vue.component('example', require('./components/UserComponents/User.vue'));

const app = new Vue({

    el: 'body',

});

This is my component User.vue i left the HTML template out for post size reason i can post it if neccesary

<script>

    export default{

        data : function () {
            return {
                users : ''
            }
        },

        methods: {


            fetchUser: function () {

                var vm = this;

                vm.$http.get('user/', function (data) {
                   vm.$set('users', data)
                })

            }
        },
        ready() {

            this.fetchUser();
        },

    }
</script>

Im getting 2 errors in the console

 vue-resource.common.js?d39b:27 0ReferenceError: Laravel is not defined(…)

(program):29 Uncaught (in promise) ReferenceError: Laravel is not defined(…)

这是我的Package.正如你所看到的,我有所有的DEP来使用vue和vue资源

{
  "private": true,
  "scripts": {
    "prod": "gulp --production",
    "dev": "gulp watch"
  },
  "devDependencies": {
    "bootstrap-sass": "^3.3.7",
    "gulp": "^3.9.1",
    "jquery": "^3.1.0",
    "laravel-elixir": "^6.0.0-9",
    "laravel-elixir-vue": "^0.1.4",
    "laravel-elixir-webpack-official": "^1.0.2",
    "lodash": "^4.14.0",
    "vue": "^1.0.26",
    "vue-resource": "^0.9.3"
  }
}

希望有人能帮我.非常感谢.

推荐答案

Try to put this on your blade, as you can see is inserted by default on app.blade on Laravel 5.3

<script>
    window.Laravel = <?php echo json_encode([
        'csrfToken' => csrf_token(),
    ]); ?>
</script>

Laravel相关问答推荐

在Laravel Livewire中,如果一个输入基于另一个唯一的字段是唯一的,如何判断验证?

如何在使用Docker容器部署Laravel 8、9、10时处理SIGTERM信号,特别是与调度程序和工作进程相关的问题?

验证判断请求的值是否存在于另一个表 Laravel 9 中

前端和管理员分开时未加载laravel 9中间件

阻止用户查看其他用户正在查看的内容的最佳方法是什么?

Laravel 5.4 中的自定义助手类

如何在 laravel 中安装 PHPExcel 库?

Laravel 5.3 auth 判断构造函数返回 false

如何从 laravel 控制器执行外部 shell 命令?

laravel 5中的配置缓存导致找不到视图

如何卸载 Laravel?

如何在 Laravel 中将秒转换为天小时分钟

使用模型工厂、一对一和一对多关系定义 Laravel 外键,而不创建不必要的模型

向 Docker 上的 Artisan 推荐方式

使用 Laravel 创建新项目会引发异常

找不到框laravel/homestead

Laravel 获取查询字符串

如何以及在哪里可以使用 laravel 存储图像?

Laravel 手动登录功能

Laravel 5 Auth注销不起作用