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 –> {{ config(‘app.name’, ‘Laravel’) }} <!– Scripts –> <!– Fonts –> <!– Styles –>
<script src=“https://code.jquery.com/jquery-3.2.1.min.js”> </head> |
CSS:
1
2 3 |
body {
background–color: lightblue !important; } |
我想看看浅蓝色的身体,但由于某种原因它不起作用。你有什么想法吗?
- 您在 yourproject/public/css 中有一个 app.css 文件,在 yourproject/public/js 中有一个 app.js 文件?
- app.css 文件位于 meetingapp/css/app.css 中,而 app.js 位于 meetingapp/resources/js/app.js… 但即使在资产中添加文件夹资源也不起作用。
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 install。安装所有前端资产(css、js 等)。如果您从未对 css 或 js 进行任何更改,则需要在终端中运行以下命令:npm run dev 或 npm run watch。这是 Laravel Mix 的更多文档。
你不会想要接触实际的 .css 文件;每当资产编译时,它都会被覆盖。使用上述命令会将所有 .scss 文件重新编译为 .css.
希望这会有所帮助!
- 我安装了 npm 并制作了 npm run dev …现在两个错误消失了,但主体的背景颜色仍然是白色。此外,现在导航栏的下拉菜单不起作用……可能是 Popper 的问题吗?
- 您需要在 resources/sass/app.scss (或您正在使用的任何 .scss 文件中)更改背景颜色。然后重新运行 npm run dev 以重新编译 css。如果您使用的是 Bootstrap,您可能需要单独拉入每个组件。或者查看有关如何从 Bootstrap 中提取完整 js 库的文档。
- 如果您有任何机会使用符号链接将 index.php 放入您的 /var/www/your-site 中,请确保也将 css 和 js 文件夹从 public 符号链接到 /var/www/your-site。
您需要编译资产。 (假设你已经安装了 npm)
运行
1
|
npm run prod – if production
|
或
1
|
npm run dev – if development
|
您还可以在编译资产之前更改文件 resources/sass/_variables.scss 中的颜色。
这个错误表示app.js和app.css的位置不正确:
“Failed to load resource: the server responded with a status of 404
(Not Found)”
解决方案:
让你的 JS 目录结构如下:/public/js/app.js
让你的 CSS 目录结构如下:/public/css/app.css
来源:https://www.codenong.com/58809807/