namespace App\Http\Livewire\Survey;
use Livewire\Component;
use \App\Models\Section as SectionModel;
class Section extends Component
{
public $questionnaireId;
public $section;
public $currentSection = 0;
public $listeners = ['nextSection'];
public function nextSection()
{
$this->currentSection++;
$this->currentSection = $this->getSections($this->currentSection);
}
public function getSections($offset = 0)
{
$this->section = SectionModel::where('questionnaire_id', $this->questionnaireId)->offset($offset)->first();
}
public function mount($questionnaireId)
{
$this->questionnaireId = $questionnaireId;
$this->getSections();
}
public function getSectionsProperty()
{
return $this->section;
}
}
这是我的componentOne.php
public function triggerNextSection()
{
$this->emit('nextSection');
}
这是component-one.blade.php
<button wire:click="triggerNextSection"
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"> Continue
</button>
当单击继续按钮时,$currentSection值增加1。
与我使用此按钮并在componentTwo中发出此事件的方式相同,这里不递增$currentSection的值。
有没有人可以帮助我如何增加这个变量的值?
我尝试发出一个带有传递参数的事件
1条答案
按热度按时间b4lqfgs41#
试着这样做: