我正在寻找一种在 Livewire 中制作弹出框/工具提示的方法,最好不使用 Vue。
到目前为止,我已经创建了一个 UserPopover Livewire 组件:
namespace App\Http\Livewire;
use App\User;
use Livewire\Component;
class UserPopover extends Component
{
public $isOpen = false;
public $user = null;
protected $listeners = [
'closeUserPopover',
'showUserPopover' => 'open',
];
public function open($username)
{
$this->user = User::whereName($username)->first();
$this->isOpen = true;
}
public function closeUserPopover()
{
$this->isOpen = false;
}
public function render()
{
return view('livewire.user-popover');
}
}
并渲染组件:
<div>
@if($isOpen)
<div class="user-popover fixed top-0 shadow bg-white p-6 text-sm">
<h3>{{ $user->name }}</h3>
<div>{{ $user->profile->bio }}</div>
</div>
@endif
</div>
在我的app.blade.php
文件中,我已将其包含在其中,@livewire('user-popover')
并且我正在调用该组件:
<a href="{{ route('users.show', $user) }}"
wire:mouseover="$emit('showUserPopover', {{ $user->name }})"
wire:mouseout="$emit('closeUserPopover')"
>
{{ $user->name }}
</a>
我不知道下一步该做什么。关于定位、可重用性和整体架构的任何想法?