首页 > 解决方案 > 为什么其他 JavaScript 文件在我的 PHP 文件中不起作用?

问题描述

单击以查看我使用 Laravel(最新版​​本)和 Vue 2 的图像。当我在 file.blade.php 页面中包含默认的 app.js(唯一有效的 js 文件)时,它可以工作。但是,如果我在与 app.js (ressource/js/app.js) 相同的路径中创建另一个 js 文件示例:apple.js,它不想找到它。

控制台谷歌浏览器:GET http://127.0.0.1:8000/js/apple.js net::ERR_ABORTED 404(未找到)

我已经尝试过的:

script src="{{URL::asset('/js/apple.js')}}" /script

script src="{{asset('/js/apple.js')}}" /script

script src="/js/apple.js" /script

最后

script src="js/apple.js" /script

我出于展示目的而取消报价。

    <!DOCTYPE html>
    <html>
    <head>
    <title></title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.css">
    <meta name="csrf-token" content="{{ csrf_token() }}">


    <style>

        body { padding-top:40px; }

    </style>


</head>
<body>





<div id="something" class="container">


    <tabs>

        <tab name="About us"  :selected="true">

            <h1>Here is the content for theabout us tab</h1>

        </tab>


        <tab name="About our Culture">

            <h1>Here is the content for the about our culture tab</h1>

        </tab>


        <tab name="About Our Vision">

            <h1>Here is the content for the about our vision tab</h1>

        </tab>

    </tabs>



</div>






<script src="{{asset('/js/apple.js')}}"></script>

</body>
</html>

标签: javascriptphplaravel

解决方案


大多数情况下,由于我们忘记编译文件而发生这种情况。确保您编译了该文件,并且它出现在公用文件夹中。
对于编译,运行命令:
npm run dev

对于持续编译,运行watch命令:
npm run watch


推荐阅读