简体   繁体   English

laravel 6 是否自动加载 jquery? 获取未捕获的类型错误

[英]Does laravel 6 auto-load jquery? Getting uncaught type error

I had this project working perfectly fine until I implemented authentication.在我实施身份验证之前,我让这个项目运行得非常好。 I composer required laravel/ui then did php artisan ui vue --auth as per the documentation here我作曲家需要 laravel/ui 然后按照这里的文档做了 php artisan ui vue --auth

Before the auth, the scripts were loading perfectly (this is a jquery table sorter plugin) and the functionality was a dream.在身份验证之前,脚本加载完美(这是一个 jquery 表排序插件),功能是一个梦想。 After the auth scaffolding, it's giving me this error:在身份验证脚手架之后,它给了我这个错误:

Uncaught TypeError: $(...).tablesorter is not a function

Here is my code at the bottom of my view:这是我视图底部的代码:

    <script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <script src="{{asset('js/jquery.tablesorter.js')}}"></script>
    <script src="{{asset('js/jquery.tablesorter.widgets.js')}}"></script>
    <script>
    $(function() {
    $("#myTable").tablesorter();
    });

    </script>

I don't work a lot with front end stuff and laravel 6 has a few features implemented that I'm sure I'm unaware of.我不经常使用前端的东西,laravel 6 实现了一些我确定我不知道的功能。 Other SO articles say that this error is generally caused by loading jquery in more than one place.其他SO文章说这个错误一般是在多个地方加载jquery导致的。 Does laravel implement jquery somewhere when doing the auth scaffolding?在进行身份验证脚手架时,laravel 是否在某处实现了 jquery? If not, what else could be giving me this error after implementing the auth?如果没有,那么在实施身份验证后还有什么可能给我这个错误? If I comment out the script line that has jquery as the "src", I get jquery is not defined and $ is not defined .如果我注释掉将 jquery 作为“src”的脚本行,我会得到jquery is not defined$ is not defined So I don't know what's going on.所以我不知道发生了什么。 Theoretically it's being double loaded but if i comment it out, it's obviously not loaded from somewhere else.理论上它是双重加载的,但如果我将其注释掉,它显然不是从其他地方加载的。

For anyone who comes across this in the future, I believe that app.js generated by laravel authentication scaffolding includes jquery within itself.对于将来遇到此问题的任何人,我相信由 laravel 身份验证脚手架生成的 app.js 本身包含 jquery。 When I removed the jquery scripts from the bottom of the view and removed the "defer" parameter in the app.js script line at the top of app.blade, the code began to work again.当我从视图底部删除 jquery 脚本并删除 app.blade 顶部的 app.js 脚本行中的“defer”参数时,代码又开始工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM