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

Commit fe29a79

Browse files
committed
Added test route
1 parent a607757 commit fe29a79

File tree

6 files changed

+91
-0
lines changed

6 files changed

+91
-0
lines changed

app/app/View/Components/Child.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\View\Components;
4+
5+
use Closure;
6+
use Illuminate\Contracts\View\View;
7+
use Illuminate\View\Component;
8+
9+
class Child extends Component
10+
{
11+
/**
12+
* Create a new component instance.
13+
*/
14+
public function __construct()
15+
{
16+
//
17+
}
18+
19+
/**
20+
* Get the view / contents that represent the component.
21+
*/
22+
public function render(): View|Closure|string
23+
{
24+
return view('components.child');
25+
}
26+
}

app/app/View/Components/Root.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\View\Components;
4+
5+
use Closure;
6+
use Illuminate\Contracts\View\View;
7+
use Illuminate\View\Component;
8+
9+
class Root extends Component
10+
{
11+
/**
12+
* Create a new component instance.
13+
*/
14+
public function __construct()
15+
{
16+
//
17+
}
18+
19+
/**
20+
* Get the view / contents that represent the component.
21+
*/
22+
public function render(): View|Closure|string
23+
{
24+
return view('components.root');
25+
}
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script setup>
2+
const childVar = ref('Hello from child component');
3+
</script>
4+
5+
<h2>Child component</h2>
6+
<div>
7+
<h3>Slot <span v-html="childVar" /></h3>
8+
{{ $slot }}
9+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script setup>
2+
const count = ref(0)
3+
4+
const emit = defineEmits(['incremented'])
5+
6+
function increment() {
7+
count.value++
8+
emit('incremented')
9+
}
10+
</script>
11+
12+
<h2>Parent component</h2>
13+
<p>Count: @{{ count }}</p>
14+
15+
<button @click="increment">Increment</button>
16+
17+
<x-child>
18+
Child Slot
19+
<p>Count: @{{ count }}</p>
20+
</x-child>

app/resources/views/slot.blade.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<x-layout>
2+
<script setup>
3+
const layoutCounter = ref(0)
4+
</script>
5+
6+
<p>Layout counter: @{{ layoutCounter }}</p>
7+
8+
<x-root @incremented="layoutCounter++" />
9+
</x-layout>

app/routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
Route::view('/refresh', 'refresh')->middleware(Refreshable::class);
3636
Route::view('/refresh-state', 'refresh-state')->middleware(Refreshable::class);
3737
Route::view('/regular-view', 'regular-view');
38+
Route::view('/slot', 'slot');
3839
Route::view('/to-vue-prop', 'to-vue-prop');
3940
Route::view('/two-way-binding', 'two-way-binding');
4041

0 commit comments

Comments
 (0)