I am having one page component which having 3 child component running inside this page component. I want to change the css/scss file when the two child component change. The problem which i am facing here that when the default component load then the first works very perfectly but when the second component come then its not changing the first css.
My template already having stacks and this stack exist in the blade where page component loads.
My code is like this
Page component
<?php
namespace App\Http\Livewire\Frontend\Page\Sharedbooking;
use Livewire\Component;
class Page extends Component
{
public $display;
public $shared;
public $booking_form_data;
public $cssfiles;
protected $listeners = [
'displayLayout',
'bookingForm'
];
public function mount()
{
$this->fill([
'display' => 'detail',
'cssfiles' => 'resources/css/page/products/products-detail.scss'
]);
}
/**
* booking form
*/
public function displayLayout($type)
{
switch($type)
{
case 'customer':
$this->display = 'customer';
$this->cssfiles = 'resources/css/page/reservation/details2.scss';
break;
case 'payment':
$this->display = 'payment';
break;
}
}
/**
* collect the booking form data
*/
public function bookingForm($formData)
{
$this->booking_form_data = $formData;
//dd($this->booking_form_data);
}
public function render()
{
return view('livewire.frontend.page.sharedbooking.page');
}
}
You can use the @push directive in your blade file to add the css file to the page. You can also use the @livewireScripts directive to add the css file to the page.
In your Page component, you can add a $cssfiles variable and set it to the css file you want to use. Then, in your blade file, you can use the @push directive to add the css file to the page.
public $cssfiles;
public function mount()
{
$this->fill([
'display' => 'detail',
'cssfiles' => 'resources/css/page/products/products-detail.scss'
]);
}
public function displayLayout($type)
{
switch($type)
{
case 'customer':
$this->display = 'customer';
$this->cssfiles = 'resources/css/page/reservation/details2.scss';
break;
case 'payment':
$this->display = 'payment';
break;
}
}
@webrobert not overkill its a different css for that component. if you are having a big application website its always wise to create one main style and rest sub style based on the main components. Its easy for front end designer also. (Main style and sub styles)