如何解决Laravel-@push指令中的脚本在父@stack指令中不可用
嗨:)这是我在这里的第一篇文章,如果我的问题不太清楚,抱歉。我试图包括所有需要澄清的问题:)
我对@push
和@stack
指令有疑问。
我的项目有一个名为admin.blade.php
的父视图/布局和各种子视图,包括一个名为datatable.blade.php
的子视图。第二个文件用于显示所有用户的数据表,该数据表需要一些JS脚本,该脚本对该特定文件(datatable.blade.php
)是唯一的,并且不必包含在其他子刀片视图文件中。>
- 在我的
datatable.blade.php
(子视图)中,我具有以下内容:
@section('page-content')
... Here I have my page contect (the table which shows all the users registered,and other information) ...
@endsection
{{-- @push directive in the child view,pushing content to the parent/master @stack directive --}}
@push('custom-scripts')
<script>
... My custom JS script here (required by the datatable in the ```page-content``` section above ...
</script>
@endpush
- 在我的父视图/布局
admin.blade.php
中,我包括以下@stack
指令:
...
<!-- theme -->
<script src="../../../assets/js/theme.js"></script>
<script src="../../../assets/js/utils.js"></script>
<script src="../../../libs/parsleyjs/dist/parsley.min.js"></script>
{{-- Datatables - Always here as these are common for all datatables,then just add JS script in page-content section --}}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.22/datatables.min.js"></script>
@stack('custom-scripts')
<!-- endbuild -->
</body>
</html>
-
但是,当访问仪表板时,我的自定义脚本代码未包含在布局admin.blade.php(父项)中,从而导致数据表缺少所需的JS代码,从而导致数据表显示不正确。
-
从我的浏览器刷新页面后,此自定义脚本JS代码脚本将按预期加载,并且布局admin.blade.php(父级)中包含的代码-也已从浏览器的控制台确认
-
是否可能会缓存没有
custom-script
的原始布局/父对象,从而导致@stack
指令无法获取所需的JS脚本? -
在这种情况下,如何加载内容,而如何
@push
指令中的JS代码呢?
任何建议都将不胜感激-谢谢! :)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。