Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

laravel - LiveWire methods not working on simple compnent

i created a new simple components for using into liveWire and i'm trying to use this component from a single route, in below simple implementation increment and decrement not working for me

route:

Route::get('/login',LoginComponent::class);

LoginComponent::class:

class LoginComponent extends Component
{
    public $count = 10;

    public function render()
    {
        return view('livewire.auth.login')->layout('livewire.auth.app');
    }

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

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

app.blade.php:

<!DOCTYPE html>
<html lang="en">

<head>
    ...

    @livewireStyles
</head>

<body>
    <div class="page-content">
        <div class="content-wrapper">
            @yield('content')
        </div>
    </div>

    @livewireScripts
</body>

</html>

and then login.blade.php:

<div>
    @section('content')
        <div class="page-content">
            <div class="content-wrapper">
                <div class="content d-flex justify-content-center align-items-center">
                    <div style="text-align: center">
                        <button wire:click="increment"> + </button>

                        <button wire:click="decrement"> - </button>

                        <h1>{{ $count }}</h1>
                    </div>
                </div>
            </div>
        </div>
    @endsection
</div>
question from:https://stackoverflow.com/questions/65641664/livewire-methods-not-working-on-simple-compnent

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I would recommend to use proper rendering methods.

return view('livewire.auth.login')
    ->extends('livewire.auth.app')
    ->section('content');

And remove @section('content') from the login.blade.php

Check the docs on Rendering Components


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...