Liveware 值不会在脚本标签中更新

Liveware value does not update in script tags

我对 Liveware 有疑问。我正在用 Liveware 构建一个滑块之类的东西,我的组件持续时间会随着时间的推移而变化。当组件更改时,持续时间会在 html 中更新,但不会在脚本标签中更新。所以 Liveware 代码工作正常,但我怎样才能让它在脚本标签中具有更新的持续时间,以便超时根据更新的组件持续时间工作?

每个组件的持续时间可能会发生变化,例如:5、7、30 等

所以我有这样的代码:

    <section class="app-content">
        {{ $component['key'] }}
        {{ $component['duration'] }}
        @include('components.test')
    </section>

这是我的脚本代码:

<script>
    document.addEventListener('livewire:load', function () {
        Livewire.on('nextComponent', duration => {
            console.log(duration);
            setTimeout(() => Livewire.emit('nextComponent', {{ $component['duration'] }} ), {{ $component['duration'] }} * 1000);
        })
        setTimeout(() => Livewire.emit('nextComponent', {{ $component['duration'] }}), {{ $component['duration'] }} * 1000);
    });
</script>

我用这个修复了它:

<script>
    window.addEventListener('newSlide', event => {
        setTimeout(() => Livewire.emit('nextComponent', event.detail.duration), event.detail.duration * 1000);
    })

    document.addEventListener('livewire:load', function () {
        setTimeout(() => Livewire.emit('nextComponent'), {{ $component['duration'] }} * 1000);
    });
</script>

并且:

$this->dispatchBrowserEvent('newSlide', ['duration' => $this->component['duration']]);