Skip to content

Commit

Permalink
added basic component example
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart Noordsij committed Oct 13, 2020
1 parent 6e46e51 commit 8a96e49
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,62 @@ This package only provides a wrapper for the `@livewireScripts`, `@livewireStyle
You can register your Livewire components like normal.

## Example
In the head
```twig
{{ livewireStyles() }}
{{ livewireScripts() }}
```

In the body
```twig
{# The Twig version of '@livewire' #}
{% livewire counter %}
{# If you wish to pass along variables to your component #}
{% livewire counter with {'count': 3} %}
```

{{ livewireScripts() }}
In resources/views/livewire/counter.twig
```twig
<div>
<div wire:click="add">+</div>
<div>{{ count }}</div>
<div wire:click="subtract">-</div>
</div>
```
In app/Http/Livewire/Counter.php
```php
<?php

namespace App\Http\Livewire;

use Livewire\Component;

class Counter extends Component
{
public $count;

public function mount($count = 1)
{
$this->count = $count;
}

public function add()
{
$this->count++;
}

public function subtract()
{
$this->count--;
}

public function render()
{
return view('livewire.counter');
}
}
```

## Todo
Expand Down

0 comments on commit 8a96e49

Please sign in to comment.