在 laravel 中显示脚本加载失败的控制台

Posted

技术标签:

【中文标题】在 laravel 中显示脚本加载失败的控制台【英文标题】:console showing script loading failed in laravel 【发布时间】:2021-08-05 04:36:15 【问题描述】:

问题(显示在控制台中)


GEThttp://127.0.0.1:8000/public/vuexy-assets/vendors/css/vendors.min.css
[HTTP/1.0 404 Not Found 580ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/css/bootstrap-extended.css
[HTTP/1.0 404 Not Found 1153ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/css/bootstrap.css
[HTTP/1.0 404 Not Found 885ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/css/core/menu/menu-types/vertical-menu.css
[HTTP/1.0 404 Not Found 2443ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/css/themes/semi-dark-layout.css
[HTTP/1.0 404 Not Found 2158ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/css/themes/dark-layout.css
[HTTP/1.0 404 Not Found 1917ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/css/components.css
[HTTP/1.0 404 Not Found 1664ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/css/colors.css
[HTTP/1.0 404 Not Found 1405ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/css/core/colors/palette-gradient.css
[HTTP/1.0 404 Not Found 2671ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/css/pages/authentication.css
[HTTP/1.0 404 Not Found 3185ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets-sep/assets/css/style.css
[HTTP/1.0 404 Not Found 3580ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/images/pages/login.png
[HTTP/1.0 404 Not Found 5053ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/vendors/js/vendors.min.js
[HTTP/1.0 404 Not Found 3878ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/js/core/app-menu.js
[HTTP/1.0 404 Not Found 4127ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/js/core/app.js
[HTTP/1.0 404 Not Found 4425ms]

GEThttp://127.0.0.1:8000/public/vuexy-assets/js/scripts/components.js
[HTTP/1.0 404 Not Found 4681ms]

Loading failed for the <script> with source “http://127.0.0.1:8000/public/vuexy-assets/vendors/js/vendors.min.js”. 127.0.0.1:8000:297:1
Loading failed for the <script> with source “http://127.0.0.1:8000/public/vuexy-assets/js/core/app-menu.js”. 127.0.0.1:8000:302:1
Loading failed for the <script> with source “http://127.0.0.1:8000/public/vuexy-assets/js/core/app.js”. 127.0.0.1:8000:303:1
Loading failed for the <script> with source “http://127.0.0.1:8000/public/vuexy-assets/js/scripts/components.js”. 127.0.0.1:8000:304:1

这是我的问题。当我加载我的网站时,它的前端 UI 消失了,只显示了基本的 html 结构。我想尽一切办法让它更正,但我做不到。

我的布局中的代码


<link rel="stylesheet" type="text/css" href=" asset('vuexy-assets/css/bootstrap.css') ">
        <link rel="stylesheet" type="text/css" href=" asset('vuexy-assets/css/bootstrap-extended.css') ">
        <link rel="stylesheet" type="text/css" href=" asset('vuexy-assets/css/colors.css') ">
        <link rel="stylesheet" type="text/css" href=" asset('vuexy-assets/css/components.css') ">
        <link rel="stylesheet" type="text/css" href=" asset('vuexy-assets/css/themes/dark-layout.css') ">
        <link rel="stylesheet" type="text/css" href=" asset('vuexy-assets/css/themes/semi-dark-layout.css') ">

        <!-- BEGIN: Page CSS-->
        <link rel="stylesheet" type="text/css" href="asset('vuexy-assets/css/core/menu/menu-types/vertical-menu.css') ">
        <link rel="stylesheet" type="text/css" href="asset('vuexy-assets/css/core/colors/palette-gradient.css') ">
        <!-- END: Page CSS-->




 <script  src=" asset('/vuexy-assets/vendors/js/vendors.min.js') "></script>
    <!-- BEGIN Vendor JS-->

    <!-- BEGIN: Page Vendor JS-->
    <script src=" asset('/vuexy-assets/vendors/js/ui/jquery.sticky.js') "></script>
    <!-- END: Page Vendor JS-->

    <!-- BEGIN: Theme JS-->
    <script src=" asset('/vuexy-assets/js/core/app-menu.js') "></script>
    <script src=" asset('/vuexy-assets/js/core/app.js') "></script>
    <script src=" asset('/vuexy-assets/js/scripts/components.js') "></script>

我的页面目前看起来像这样

我尝试过的

install npm 
npm run div
composer require laravel/ui
php artisan install  bootstrap ui

我也尝试安装yarn,并且sass-loader也从11.0.0降级为“sass-loader”:“10.1.1”

【问题讨论】:

您好,请检查您是否在这里获得了正确的路径 asset('vuexy-assets/css/bootstrap.css') 另外,您可以查看开发工具并检查元素是否应用了css。 这是控制台上的路径 GET 127.0.0.1:8000/public/vuexy-assets/css/bootstrap.css 我解决了。通过从我的链接中删除 \public。 太棒了:-)。把它写成答案并接受它,这样如果有人遇到类似的事情,他们会很容易找到答案。 【参考方案1】:

默认情况下,Laravel 的资产助手指向应用程序文件夹中的公用文件夹。如果你的资产放在那里,那么你的资产路径应该是这样的。

<a href=" asset('vuexy-assets/css/components.css') "></a>

代替

<a href=" asset('/vuexy-assets/css/components.css') "></a>

如果您的资产在公共目录之外,请在该目录和公共目录之间建立一个魔术链接。

【讨论】:

【参考方案2】:

重写链接

<a href="asset(public/vuexy-assets/css/components.css')"></a>

<a href="asset(vuexy-assets/css/components.css')"></a>

这将纠正以下错误。

【讨论】:

以上是关于在 laravel 中显示脚本加载失败的控制台的主要内容,如果未能解决你的问题,请参考以下文章

Ionic V4 - Build Prod “找不到 cordova.js 脚本标签。插件加载可能失败。”

“加载失败!”控制台开发者谷歌

Axios 响应数据未加载到 Laravel 中的 Vue 组件上

laravel5.4 后台控制器提示前台显示问题

<scripts> 节点 js 加载失败

Vuex Laravel 加载所有数据