为什么 Laravel Livewire 中的模式不关闭?

Chr*_*DLH 3 laravel eloquent bootstrap-modal bootstrap-4 laravel-livewire

我正在使用 laravel livewire 删除两个表中的记录,问题是模式,记录正在被删除,但模式仍然显示。

\n

奇怪的是,当我注释其中一行代码来删除数据时,它起作用了!

\n

我正在使用 Bootstrap 4.1

\n

这是我的功能:

\n
    public function delete($id)\n    {\n        DB::beginTransaction();\n        try \n        { \n            // If I comment on any of the following two lines (it doesn't matter what line it is), it works! \n\n            DetalleRamComputadora::where('fk_computadora', '=', $id)->delete();\n            Computadora::where('id', '=', $id)->delete();\n\n            DB::commit();\n            $this->emit('confirm'); // Close modal "confirm"\n            session()->flash('success', 'Registro eliminado con \xc3\xa9xito');\n\n        } catch (\\Throwable $th) {\n            DB::rollBack();\n            $this->emit('confirm'); // Close modal "confirm"\n            session()->flash('error', 'Ocurri\xc3\xb3 un error y no se almacen\xc3\xb3 el registro');\n        }\n    }\n
Run Code Online (Sandbox Code Playgroud)\n

这是从 Livewire 关闭模式的脚本:

\n
window.livewire.on('confirm', () => {\n     $('#delete_confirm').modal('hide');\n}); \n
Run Code Online (Sandbox Code Playgroud)\n

请帮帮我!!

\n

Chr*_*DLH 8

我能够解决这个问题。只有我在模态的 div 中添加了这段代码

**wire:ignore.self**

<div wire:ignore.self class="modal fade" id="delete_confirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    ...
</div>
Run Code Online (Sandbox Code Playgroud)