# Wire:stream 顯示前端問題 ### 環境 > Livewire 3.0.9 > Larvel 10.28.0 > PHP 8.2.8 > MariaDB 10.4.21 </br> 當使用wire:stream回傳到前端畫面時,當它資料傳遞結束後,會將顯示的值也消失。 **Demo :** 後端: ``` public $a = [1, 2, 3, 4]; function ttt() { foreach ($this->a as $b) { $this->stream(to: 'aaa', content: $b); sleep(1); } } ``` 前端: ``` <div> <button wire:click="ttt">Start</button> <span wire:stream="aaa"></span> </div> ``` </br> </br> ## 解決方法 * #### 使用 Renderless 讓頁面不要更新。 ``` use Livewire\Attributes\Renderless; #[Renderless] function ttt() { foreach ($this->a as $b) { $this->stream(to: 'aaa', content: $b); sleep(1); } } ``` </br> * #### 使用 wire:ignore 阻止 Livewire 更新頁面的一部分,讓我們將有wire:stream的這塊不要更新。 ``` <div> <button wire:click="ttt">Start</button> <span wire:stream="aaa" wire:ignore>{{ $a }}</span> </div> ``` </br> * #### 將要顯示的值代入變數後,顯示於前端(不推,會造成多餘的程式碼) 將最終顯示的值也放置前端,但前提是它要有值。 若是用$this->a = $this->stream(to: 'aaa', content: '1232'); $this->a 會因此變成NULL,前端最後還是會沒有值。 ``` <div> <button wire:click="ttt">Start</button> <span wire:stream="aaa">{{ $a }}</span> </div> ```