简体   繁体   English

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

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

Click to see the image I work with Laravel(last version) and Vue 2. When I include default app.js (the only js files that work) in my file.blade.php page it work. 单击以查看我使用Laravel(最新版​​本)和Vue 2 的图像 。当我在file.blade.php页面中包含默认app.js(唯一起作用的js文件)时,它可以工作。 But if I create a other js file example: apple.js in the same path than app.js (ressource/js/app.js),it doesn't want to find it. 但是,如果我创建另一个js文件示例:apple.js与app.js(ressource / js / app.js)位于同一路径,则它不想找到它。

Console google chrome : GET http://127.0.0.1:8000/js/apple.js net::ERR_ABORTED 404 (Not Found) 控制台Google Chrome:GET http://127.0.0.1:8000/js/apple.js net :: ERR_ABORTED 404(未找到)

What I have already tried: 我已经尝试过的:

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

AND

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

AND

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

AND FINALLY 最后

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

I take off quote for display purpose. 我以报价为目的。

    <!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>

Most of the time it happens due to we forget to compile the file. 大多数情况下,由于我们忘记编译文件,因此发生这种情况。 Make sure you compile the file and it appears in public folder. 确保编译该文件,并且该文件显示在公用文件夹中。
For compilation, run command: 对于编译,运行命令:
npm run dev

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

Try using this if you are using it in blade file. 如果在刀片文件中使用它,请尝试使用它。

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

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

Change directory structure resource/js/apple.js to public/js/apple.js 将目录结构resource/js/apple.jspublic/js/apple.js

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

This will work if your directory structure is like this: /public/js/apple.js 如果您的目录结构是这样的,那么它将起作用: /public/js/apple.js

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

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