如何让jQuery与Laravel一起工作?

问题描述 投票:2回答:1

我正在尝试让jQuery与Laravel 5.4一起使用。我用npm安装了jQuery。我在同一个文件夹中有两个文件:app.jsbootstrap.js。从app.js我导入文件bootstrap.js

require('./bootstrap');

bootstrap.js我导入jQuery:

window.$ = window.jQuery = require('jquery');

我尝试时仍在我的刀片视图中:

<script>
    $(document).ready(function () {
        console.log('jQuery is working!');
    });
</script>

我收到一个引用错误,告诉我“$未定义”。

我知道我做错了什么?先感谢您。

jquery laravel laravel-5
1个回答
1
投票

你有没有把它包括在你的视野中?你需要输入这样的东西:

<script src="{{ mix('js/app.js') }}"></script>
© www.soinside.com 2019 - 2024. All rights reserved.