我有一个组件,它以display_name和ip作为参数,在mount方法中,我用3个数据包ping主机,以检查它是否正常。所以我使用了懒惰加载来加速页面加载。
现在,当我使用多个组件时。
当页面加载时,所有组件都停留在占位符视图中,直到最后一个组件结束ping,然后它们将同时更改为主视图。
我正在寻找一种方法来设置组件以单独加载,而无需等待其他组件。
example of what i want
这是我的密码
仪表板刀片
<livewire:dashboard.ping-state name="host1" host="192.168.1.100" lazy key="1" />
<livewire:dashboard.ping-state name="host2" host="192.168.1.50" lazy key="6" />
<livewire:dashboard.ping-state name="host3" host="192.168.1.52" lazy key="7" />
<livewire:dashboard.ping-state name="host4" host="192.168.1.59" lazy key="3" />
ping状态
<?php
namespace App\Livewire\Dashboard;
use Acamposm\Ping\Ping;
use Acamposm\Ping\PingCommandBuilder;
use Jantinnerezo\LivewireAlert\LivewireAlert;
use Livewire\Component;
class PingState extends Component
{
use LivewireAlert;
public string $name;
public string $host;
public $avg = 0;
public string $host_ok;
public function mount(string $name, string $host)
{
$this->name = $name;
$this->host = $host;
$this->ping();
}
public function ping()
{
$command = (new PingCommandBuilder($this->host))->count(3);
$ping = (new Ping($command))->run();
$this->avg = optional($ping)->latency;
$this->host_ok = $ping->host_status == 'Ok';
if(!$this->host_ok)
{
$this->alert("warning",$this->name,["timer"=>10000]);
$this->dispatch("unreachableHost");
}
}
public function placeholder()
{
return view('placeholders.ping-state',["name"=>$this->name]);
}
public function render()
{
return view('livewire.dashboard.ping-state');
}
}