我有一个名为 all.blade.php 的文件,如下所示:
@component('admin.layouts.content' , ['title' => 'example file'])
@slot('breadcrumb')
<li class="breadcrumb-item active">Example File</li>
@endslot
...
@endcomponent
@push('scripts')
<script>
Swal.fire({
title: 'Do you want to save the changes?',
showDenyButton: true,
showCancelButton: true,
confirmButtonText: 'Save',
denyButtonText: `Don't save`,
}).then((result) => {
/* Read more about isConfirmed, isDenied below */
if (result.isConfirmed) {
Swal.fire('Saved!', '', 'success')
} else if (result.isDenied) {
Swal.fire('Changes are not saved', '', 'info')
}
})
</script>
@endpush
这是 content.blade.php:
@extends('admin.master')
@section('content')
{{ $slot }}
@endsection
这是 master.blade.php:
<!DOCTYPE html>
<html>
<head>
...
@stack('scripts')
</head>
<body>
@yield('content')
</body>
</html>
现在的问题是 @push('scripts') ... @endpush 不起作用并且没有显示甜蜜的警报消息。
那么这里出了什么问题呢?我怎样才能解决这个问题并在刀片上一起调用@component和@push?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
尝试
Ctrl+U检查该组件是否呈现到其位置。另请注意,如果您使用的是 Swallibrary JS 库,那么实际的 Swallibrary 代码会在调用 fire() 函数之前加载。最后请检查浏览器控制台选项以确定是否是某些 JS 错误,而不是刀片错误。
调换
@push和@component的顺序@push('scripts') @endpush @component('admin.layouts.content' , ['title' => 'example file']) @slot('breadcrumb')另一种选择是将主转换为组件
... {{ $scripts ?? '' }} {{ $slot }}并将内容转换为组件
然后你可以将all.blade.php编写为