How to fix error 404 with app.js and app.css in Laravel?
我正在使用 Laravel 6 和 Bootstrap 4。
我做了一个小应用程序,我试图在 CSS 文件中更改正文的背景颜色,但我发现它不起作用。
于是我检查了开发者的工具,发现app.js和css/app.css有两个错误
"Failed to load resource: the server responded with a status of 404 (Not Found)"
我尝试在 CSS 路径前添加"/",但失败了。
视图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <!doctype html> <html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- CSRF Token --> <meta name="csrf-token" content="{{ csrf_token() }}"> {{ config('app.name', 'Laravel') }} <!-- Scripts --> <script src="{{ asset('js/app.js') }}" defer> <!-- Fonts --> <link rel="dns-prefetch" href="//fonts.gstatic.com"> <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet"> <!-- Styles --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> <link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css"> <script src="https://code.jquery.com/jquery-3.2.1.min.js"> <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 src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"> </head> <body style="overflow: hidden;"> @include('../inc/navbar') <main class="py-4"> @yield('content') </main> @include('../inc/footer') </body> </html> |
CSS:
1 2 3 | body { background-color: lightblue !important; } |
我想看看浅蓝色的身体,但由于某种原因它不起作用。你有什么想法吗?
I was trying to change the background color of the body in the css file but I noticed that it didn't work.
如果这是 Laravel 的全新安装,您需要运行
你不会想要接触实际的
希望这会有所帮助!
您需要编译资产。 (假设你已经安装了 npm)
运行
1 | npm run prod - if production |
或
1 | npm run dev - if development |
您还可以在编译资产之前更改文件
这个错误表示
"Failed to load resource: the server responded with a status of 404
(Not Found)"
解决方案:
让你的 JS 目录结构如下:
让你的 CSS 目录结构如下: