我正在尝试学习VueJS和Twig。我制作了自己的(只是为了好玩)MVC,工作正常,问题在于无法包含JS或CSS文件。
当我按 CTRL+u 并查看我的源代码时,我单击我的 javascript 文件,然后页面以正确的 URL 重新加载,但我仍然会看到我的索引页...
我不知道是什么原因造成的,也不知道如何解决这个问题。有人对如何解决这个问题有任何想法吗?
根htaccess 公共 htaccess
我的根 htaccess 文件是:
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
我的公用文件夹中的 htaccess 文件是
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /public
RewriteCond %{REQUEST_FILENAME}% !-d
RewriteCond %{REQUEST_FILENAME}% !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
我的布局(索引)页面是这样的:
<!DOCTYPE html>
<html>
<head>
<title>Beta</title>
<link rel="stylesheet" href="../../public/css/style.css" />
<script src="../../node_modules/vue/dist/vue.min.js"></script>
<script src="../../public/js/scripts.js"></script>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
如前所述,当我单击我的 CSS 或 JS 文件时,我在源代码中看到以下内容:
<!DOCTYPE html>
<html>
<head>
<title>Beta</title>
<link rel="stylesheet" href="../../public/css/style.css" />
<script src="../../node_modules/vue/dist/vue.min.js"></script>
<script src="../../public/js/scripts.js"></script>
</head>
<body>
Hello there!
</body>
</html>
希望有人能帮助我!
更新:我把我的htaccess改成了这个:
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?/$1 [L,NC]
</IfModule>
现在我的CSS和JS是可见的,但是node_modules(Vue)仍然显示出这种只显示索引页源代码的奇怪行为。
明显的菜鸟错误!
您不能包含"node_modules"文件夹中的内容。我使用 GULP 将所有内容包含并编译到我的一个可公开访问的文件夹中,现在我可以很好地包含它们!