如何根据 Laravel Livewire 中的其他输入设置输入值?
How to set input value based on other input in Laravel Livewire?
我必须输入数字,
- 评分
- 汇率反转
我想做什么:
当用户输入汇率时,它应该计算(1/rate)反向,并在反向输入中填写。
<!-- Rate -->
<x-input-group type="number" min="0" step="0.0001"/>
<!-- Reverse -->
<x-input-group type="number min="0" step="0.0001"/>
我知道它应该做这样的事情:
<!-- Rate -->
<x-input-group type="number" min="0" wire:focusout="reverse" step="0.0001"/>
<!-- Reverse -->
<x-input-group type="number min="0" step="0.0001"/>
在我的组件中:
public function reverse()
{
$reverse = floatval(1 / $this->rate);
// here I don't know how to change reverse input value
}
现在,如何在视图中更改反向值?
你可以试试这个
<!-- Rate -->
<x-input-group type="number" wire:model.lazy="rate" min="0" step="0.0001"/>
<!-- Reverse -->
<x-input-group type="number wire:model="reverse" min="0" step="0.0001"/>
// in component
public $rate, $reverse;
public function updatedRate($value)
{
$this->reverse = floatval(1 / $this->rate);
}
我必须输入数字,
- 评分
- 汇率反转
我想做什么:
当用户输入汇率时,它应该计算(1/rate)反向,并在反向输入中填写。
<!-- Rate -->
<x-input-group type="number" min="0" step="0.0001"/>
<!-- Reverse -->
<x-input-group type="number min="0" step="0.0001"/>
我知道它应该做这样的事情:
<!-- Rate -->
<x-input-group type="number" min="0" wire:focusout="reverse" step="0.0001"/>
<!-- Reverse -->
<x-input-group type="number min="0" step="0.0001"/>
在我的组件中:
public function reverse()
{
$reverse = floatval(1 / $this->rate);
// here I don't know how to change reverse input value
}
现在,如何在视图中更改反向值?
你可以试试这个
<!-- Rate -->
<x-input-group type="number" wire:model.lazy="rate" min="0" step="0.0001"/>
<!-- Reverse -->
<x-input-group type="number wire:model="reverse" min="0" step="0.0001"/>
// in component
public $rate, $reverse;
public function updatedRate($value)
{
$this->reverse = floatval(1 / $this->rate);
}