看了一下 Page 源码,大概梳理了一下按钮点击的流程:
当你按下 Enable disable
按钮之后,会触发 $wire:target=mountAction('enableDisable')
,mountAction() 方法调用了 $this->getMountedAction()
,最终会去查找 cacheActions()
方法,其中有这么一段代码:
protected function cacheActions(): void
{
$actions = Action::configureUsing(
Closure::fromCallable([$this, 'configureAction']),
fn (): array => $this->getActions(),
);
...
也就是说,你如果没有在 getActions()
中对其注册,moutAction() 是无法通过 $action = $this->getMountedAction();
这个语句获取到 $action, 也就无法在据此进行后续 dispatchBrowserEvent 操作
public function mountAction(string $name)
{
$this->mountedAction = $name;
$action = $this->getMountedAction();
if (! $action) {
return;
}
if ($action->isDisabled()) {
return;
}
$this->cacheForm(
'mountedActionForm',
fn () => $this->getMountedActionForm(),
);
if ($action->hasForm()) {
$action->callBeforeFormFilled();
}
app()->call($action->getMountUsing(), [
'action' => $action,
'form' => $this->getMountedActionForm(),
]);
if ($action->hasForm()) {
$action->callAfterFormFilled();
}
if (! $action->shouldOpenModal()) {
return $this->callMountedAction();
}
$this->resetErrorBag();
$this->dispatchBrowserEvent('open-modal', [
'id' => 'page-action',
]);
}