我正在尝试让jQuery与Laravel 5.4一起使用。我用npm安装了jQuery。我在同一个文件夹中有两个文件:app.js
和bootstrap.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>
我收到一个引用错误,告诉我“$未定义”。
我知道我做错了什么?先感谢您。
你有没有把它包括在你的视野中?你需要输入这样的东西:
<script src="{{ mix('js/app.js') }}"></script>