Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Livewire侦听来自组件类的每个响应_Javascript_Laravel_Laravel Livewire - Fatal编程技术网

Javascript Livewire侦听来自组件类的每个响应

Javascript Livewire侦听来自组件类的每个响应,javascript,laravel,laravel-livewire,Javascript,Laravel,Laravel Livewire,我正在构建一个组件,并在下拉列表中使用Select2。以下是我的看法: <div x-data="{ }" x-init="() => { $('.select2').select2(); $('.select2').change(e => { $wire.set('name', e.target.value); Livewire.hook('message.processed', (m, comp

我正在构建一个组件,并在下拉列表中使用Select2。以下是我的看法:

<div x-data="{ }" x-init="() => {
    $('.select2').select2();
    $('.select2').change(e => {
        $wire.set('name', e.target.value);

        Livewire.hook('message.processed', (m, component) => {
            $('.select2').select2();
        })

    })
}" class="row mt-5">
<form wire:submit.prevent="send">
    <div class="col-12">
        <p><strong>{{ $name }}</strong></p>
        <br />
        <select wire:model="name" class="form-control select2">
            <option value="">-----select-----</option>
            @foreach($names as $name)
                <option value="{{ $name }}">{{ $name }}</option>
            @endforeach
        </select>
        @error('name') <span class="error">{{ $message }}</span> @enderror
    </div>
    <div class="mt-4 col-12">
        <button type="submit" class="btn btn-success">
            Submit
        </button>
    </div>
</form>
在我的alpine代码中,我使用message.processed钩子重新应用Select2功能,否则组件重新渲染会把它搞砸。现在有一种情况,如果在页面加载和组件类响应时首先提交表单,并且出现验证错误,那么这个钩子永远不会发生,我将失去Select2功能。我可以在javascript端做些什么来监听组件类的每个响应,以重新应用select2,因为我在文档中找不到它。

您可以使用wire:ignore,而不必重新应用select2。在该页面中搜索Select2