我有以下超文本标记语言:
<div class="relative lg:inline-flex bg-gray-100 rounded-xl">
<x-dropdown>
<x-slot:trigger>
<button>.......</button>
</x-slot:trigger>
<x-dropdown-item href='/' :active="request()->is('/')">All</x-dropdown-item>
@foreach($categories as $category)
<x-dropdown-item href="/category/{{ $category->slug }}"
:active="request()->is('/category/'.$category->slug)"> {{ ucwords($category->name) }}
</x-dropdown-item>
@endforeach
</x-dropdown>
</div>
但在我的DropDown-Item组件中没有分配Active属性:
@props(['active' => false])
@php
$classes = 'block text-left px-3 text-sm leading-5 hover:bg-blue-500 focus:bg-blue-500 hover:text-white focus:text-white';
if ($active) {
dd($active);
$classes .=' bg-blue-500 text-white';
}
@endphp
<a {{ $attributes(['class' => $classes]) }}>{{ $slot }}</a>
我希望我的dd在active属性设置为true时触发,但它从未触发
我try 创建一个Dropdown Item类:
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class DropdownItem extends Component
{
/**
* Create a new component instance.
*/
public function __construct(...$args)
{
dd($args);
// $this->active = true;
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.dropdown-item', [
// 'active' => $this->active
]);
}
}
但是$args返回[],所以也没有属性,我不知道为什么,我判断了laravel 10的官方文档,但似乎一切正常.如果我在班上全力以赴,一切都能正常工作