簡體   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