gpt4 book ai didi

Livewire Wire Elements Modal not triggering events(带电导线元件模式不触发事件)

转载 作者:bug小助手 更新时间:2023-10-25 17:58:26 31 4
gpt4 key购买 nike



I am using Wire Elements Modal, It is working properly but events are not getting triggered from modal component. My modal is like below

我正在使用Wire Elements模式,它工作正常,但事件不是从模式组件触发的。我的模式如下所示


class AddUser extends ModalComponent
{
public function render()
{
$this->emit('refresh');
$this->dispatchBrowserEvent('contentChanged');
return view('add-user');
}
}

In above component two events are emitted and below code listens to them. But below code is not triggered at all. If I use normal Livewire component then below code is triggered without any issue.
The problem is only if I use WireElements/modal component.

在上面的组件中,发出两个事件,下面的代码监听它们。但下面的代码根本不会被触发。如果我使用正常的Livewire组件,那么下面的代码被触发时没有任何问题。只有当我使用WireElements/MODEL组件时,问题才会出现。


In layout file I have listener like below

在布局文件中,我有如下监听程序


<script>
Livewire.on('refresh', () => {
//code
})
window.addEventListener('contentChanged', (e) => {
//code
});
</script>

This works in normal livewire component but not in modal.

这在普通的Livewire组件中有效,但在模式中不起作用。


更多回答

Your question is slightly vague. What is the expected behaviour? That some JS is executed each time the modal element renders?

你的问题有点含糊其辞。预期的行为是什么?每次呈现modal元素时都会执行一些JS?

When do you want this code to run? On the initial mount of the component?

您希望此代码在什么时候运行?在组件的初始装载上?

Initial mount as well as subsequent requests

初始装载以及后续请求

优秀答案推荐

The initial render will not handle emits or browser events since at that point there isn't even a rendered document. What you can do is use wire:init, to trigger your events in the first render:

初始呈现不会处理发射或浏览器事件,因为此时甚至没有呈现的文档。您可以使用wire:init在第一次渲染中触发事件:


class AddUser extends ModalComponent
{
public function render()
{
$this->sendEvents();
return view('add-user');
}

public function sendEvents()
{
$this->emit('refresh');
$this->dispatchBrowserEvent('contentChanged');
}
}

<div wire:init="sendEvents">

</div>

I have tested this myself and it triggers each request cycle.

我自己测试过,它会触发每个请求周期。


更多回答

I will try and update

我会试着更新的

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com