【发布时间】:2021-04-09 20:22:18
【问题描述】:
Q.1) 我想将具有多个输入字段的表单拆分为大约 5 个组件,因为输入字段和用户体验的原因很多。我正在考虑填写表单的所有内容直到最后一个组件并将输入值保存到服务器的屏幕。最好的方法是什么?只使用刀片会更好吗?
Q.2)在这种情况下,有没有办法将参数从子组件传递和保持到父组件?
step1.php(组件)
class Step1 extends Component
{
public $step = 1;
public $step1DataTitle; //test reason
public $step2DataTitle;
public $step3DataTitle;
public $step4DataTitle;
public $step5DataTitle;
public $step6DataTitle;
protected $listeners = ['moveBack' => 'moveBack', 'moveNext' => 'moveNext'];
public function render()
{
return view('livewire.sending.step1', ['step' => $this->step]);
}
public function moveBack()
{
$this->step = $this->step - 1;
}
public function moveNext()
{
$this->step = $this->step + 1;
}
step1.blade.php
<div>
@switch($step)
@case(1)
@livewire('sending.step1')
@break
@case(2)
@livewire('sending.step2')
@break
@case(3)
@livewire('sending.step3')
@break
@case(4)
@livewire('sending.step4')
@break
@case(5)
@livewire('sending.step5')
@break
@default
@livewire('sending.default')
@endswitch
</div>
每个视图文件都有方向按钮。 How to use $emitUp
<input wire:model="step5DataTitle"/> //test reason
<div class="flex justify-between">
<button wire:click="$emitUp('moveBack')"/>
<button wire:click="$emitUp('moveNext')"/>
</div>
【问题讨论】:
标签: laravel laravel-blade laravel-livewire