Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Added test route
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Jan 26, 2024
1 parent a607757 commit fe29a79
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/app/View/Components/Child.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\View\Components;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class Child extends Component
{
/**
* Create a new component instance.
*/
public function __construct()
{
//
}

/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.child');
}
}
26 changes: 26 additions & 0 deletions app/app/View/Components/Root.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\View\Components;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class Root extends Component
{
/**
* Create a new component instance.
*/
public function __construct()
{
//
}

/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.root');
}
}
9 changes: 9 additions & 0 deletions app/resources/views/components/child.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup>
const childVar = ref('Hello from child component');
</script>

<h2>Child component</h2>
<div>
<h3>Slot <span v-html="childVar" /></h3>
{{ $slot }}
</div>
20 changes: 20 additions & 0 deletions app/resources/views/components/root.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script setup>
const count = ref(0)
const emit = defineEmits(['incremented'])
function increment() {
count.value++
emit('incremented')
}
</script>

<h2>Parent component</h2>
<p>Count: @{{ count }}</p>

<button @click="increment">Increment</button>

<x-child>
Child Slot
<p>Count: @{{ count }}</p>
</x-child>
9 changes: 9 additions & 0 deletions app/resources/views/slot.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<x-layout>
<script setup>
const layoutCounter = ref(0)
</script>

<p>Layout counter: @{{ layoutCounter }}</p>

<x-root @incremented="layoutCounter++" />
</x-layout>
1 change: 1 addition & 0 deletions app/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Route::view('/refresh', 'refresh')->middleware(Refreshable::class);
Route::view('/refresh-state', 'refresh-state')->middleware(Refreshable::class);
Route::view('/regular-view', 'regular-view');
Route::view('/slot', 'slot');
Route::view('/to-vue-prop', 'to-vue-prop');
Route::view('/two-way-binding', 'two-way-binding');

Expand Down

0 comments on commit fe29a79

Please sign in to comment.