wire:offline
状況によっては、ユーザーがインターネットに接続されているかどうかを知ることが役立つ場合があります。In certain circumstances it can be helpful for your users to know if they are currently connected to the internet.
たとえば、Livewire上にブログプラットフォームを構築した場合、オフライン時にユーザーに何らかの方法で通知し、Livewireがデータベースに保存できない状態でブログ投稿全体を作成してしまうのを防ぎたい場合があります。If for example, you have built a blogging platform on Livewire, you may want to notify your users in some way if they are offline so that they don't draft an entire blog post without the ability for Livewire to save it to the database.
Livewireでは、wire:offline
ディレクティブを提供することで、これを簡単に実現できます。Livewireコンポーネントの要素にwire:offline
を付加すると、デフォルトでは非表示になり、Livewireがネットワーク接続の中断を検出し、利用できなくなった場合にのみ表示されます。ネットワーク接続が回復すると、再び非表示になります。Livewire make this trivial by providing the wire:offline
directive. By attaching wire:offline
to an element in your Livewire component, it will be hidden by default and only be displayed when Livewire detects the network connection has been interrupted and is unavailable. It will then disappear again when the network has regained connection.
例:For example:
<p class="alert alert-warning" wire:offline>
Whoops, your device has lost connection. The web page you are viewing is offline.
</p>