What seems to be the problem:
Emiting an event from mount()
on a component is not working. I’m able to emit through a method which is called via wire:click="update"
but I also need to emit the event once the component is done loading.
Steps to Reproduce:
Here’s the relevant code…
I have a route:
Route::livewire('/contract-forms/{contract_form}', 'admin.contracts.view-contract-form')->layout('layouts.app-header')->name('contract-forms.view');
I have this in the component for this route:
<?php
namespace App\Http\Livewire\Admin\Contracts;
use App\ContractForm;
use Livewire\Component;
class ViewContractForm extends Component
{
public $contract_form;
public function mount(ContractForm $contract_form)
{
$this->contract_form = $contract_form->toArray();
$this->emit('updateTitle', $this->contract_form['title']);
}
public function render()
{
return view('livewire.admin.contracts.view-contract-form');
}
}
My layout file, app-header.blade.php calls @livewire('admin.title')
component which looks like:
<?php
namespace App\Http\Livewire\Admin;
use Livewire\Component;
class Title extends Component
{
public $title;
protected $listeners = ['updateTitle' => 'update'];
public function render()
{
return view('livewire.admin.title');
}
public function update($updateTitle)
{
$this->title = $updateTitle;
}
}
Are you using the latest version of Livewire:
Yes, v1.1.0