laravel – livewire 3 – dispatch 給 JS 出現錯誤:Uncaught TypeError: Illegal invocation

如果在前端設置監聽 wire 的事件並取名為 message 瀏覽器會出現下列錯誤警告。

    Uncaught TypeError: Illegal invocation
    at l._onMessage (<anonymous>:1:60569)
    at dispatchEvent (livewire.js?id=f121a5df:4505:12)
    at dispatch3 (livewire.js?id=f121a5df:4472:5)
    at livewire.js?id=f121a5df:8815:9
    at Array.forEach (<anonymous>)
    at dispatchEvents (livewire.js?id=f121a5df:8809:16)
    at Array.<anonymous> (livewire.js?id=f121a5df:8786:5)
    at trigger (livewire.js?id=f121a5df:433:34)
    at Component.processEffects (livewire.js?id=f121a5df:4392:7)
    at handleResponse (livewire.js?id=f121a5df:3990:24)

這是我的程式碼,使用了 $this->dispatch("message", ...)

我的前端 JS

如圖片所述,不要使用 “message” 我猜應該是 livewire 已經內定名稱了,但是錯誤沒有被 livewire 友善的捕獲。建議名稱換掉就解決這個問題。

發表迴響