繁体   English   中英

为什么其他JavaScript文件在我的PHP文件中不起作用?

[英]Why do other JavaScript files not work in my PHP file?

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

控制台Google Chrome: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>

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

要进行连续编译,请运行watch命令:
npm run watch

如果在刀片文件中使用它,请尝试使用它。

@section('script')
<script .....></script>
@endsection

尝试在公共目录而不是资源目录中创建一个文件夹(将其命名为您想要的名称,通常我将其命名为js,因为它包含js文件),而不是在resources目录中,然后使用以下命令调用该文件:
<script type='text/javascript' src="{{ asset('/js/apple.js') }}"></script>

将目录结构resource/js/apple.jspublic/js/apple.js

<script type="text/javascript" src="{{ URL::asset('js/apple.js') }}"></script>

如果您的目录结构是这样的,那么它将起作用: /public/js/apple.js

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM