在Laravel7应用程序中添加了jquery提升错误

在Laravel7应用程序中添加了jquery提升错误,laravel,Laravel,在我新的Laravel7应用程序中,我添加了jquery,其中包含了thread命令和 在package.json中,我有: "dependencies": { "bootstrap": "^4.5.0", "font-awesome": "^4.7.0", "jquery": "^3.5.1", "turbolin

在我新的Laravel7应用程序中,我添加了jquery,其中包含了thread命令和 在package.json中,我有:

"dependencies": {
    "bootstrap": "^4.5.0",
    "font-awesome": "^4.7.0",
    "jquery": "^3.5.1",
    "turbolinks": "^5.2.0"
}
但当我在我的参考资料/js/app.js中设置行时:

require('jquery');

require('./bootstrap');

var Turbolinks = require("turbolinks")
Turbolinks.start()

console.log('!! resources/js/app.js jQuery.fn.tooltip.Constructor.VERSION::')
console.log(jQuery.fn.tooltip.Constructor.VERSION)
我有一个错误:

app.js:30245 Uncaught ReferenceError: jQuery is not defined
我还试着用台词:

console.log($.fn.tooltip.Constructor.VERSION)
但也有类似的错误

我想我不必在我的resources/views/layouts/app.blade.php文件中设置指向jquery.js文件的链接

如何修复它?

执行
require('jquery')
,只会使用其
模块返回一个新的jquery对象。exports
。它不会在全局命名空间中注册
$
jQuery
。要能够使用
$(“#按钮”)
,您需要在全局命名空间中注册
$

bootstrap.js
中或在
app.js
中使用任何jquery之前,您可以在全局范围(
窗口
对象)中注册它们。从默认laravel安装附带的boiler plate中可以看到,您可以这样注册jquery:

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */

try {
    window.$ = window.jQuery = require('jquery');
} catch (e) {}