简体   繁体   中英

Laravel form submit not working (Livewire + Turbolinks)

I needed for my project the livewire package in, but have not used before. Some livewire components do not work without refreshing the page, i did not understand the reason for this.

<form wire:submit.prevent="login_method">
    <input type="text" wire:model="login.email" id="email">
    <input type="password" wire:model="login.password" id="password">
    <button type="submit">Login</button>
</form>
class Login extends Component
{
    public $login;

    public function login()
    {
        return dd($this->$login);
    }
    
    public function render()
    {
        return view('livewire.auth.login')->extends('layout.default');
    }
}

Note: I use Turbolinks (SPA). To switch between pages without refreshing the browser.

When I disable Turbolinks, form submission works, but when Turbolinks is active, livewire components are loaded when switching between pages, but the actions do not work.

Laravel 8.12 / Livewire 2.3 / Turbolinks 5.2

Please change the method name in form tag from login_method to login as show in code below.

<form wire:submit.prevent="login">
    <input type="text" wire:model="login.email" id="email">
    <input type="password" wire:model="login.password" id="password">
    <button type="submit">Login</button>
</form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM