Why Laravel-livewire 'wire:model' not working?

做~自己de王妃 提交于 2020-12-14 23:39:45

问题


I am using Laravel 8.

My Livewire Controller

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class SearchDropdown extends Component
{
    public $search = 'hello there';
    public function render()
    {
        return view('livewire.search-dropdown');
    }
}

Livewire blade

<div class="relative mt-3 md:mt-0">
    <input wire:model="search" type="text" class="bg-gray-800 text-sm rounded-full w-64 px-4 pl-8 py-1 focus:outline-none focus:shadow-outline" placeholder="Search">
    <div class="absolute top-0">
        <svg class="fill-current w-4 text-gray-500 mt-2 ml-2" viewBox="0 0 24 24"><path class="heroicon-ui" d="M16.32 14.9l5.39 5.4a1 1 0 01-1.42 1.4l-5.38-5.38a8 8 0 111.41-1.41zM10 16a6 6 0 100-12 6 6 0 000 12z"/></svg>
    </div>
    <div class="absolute text-sm bg-gray-800 rounded w-64 mt-4">
        <ul>
            <li class="border-b border-gray-700">
                <a href="#" class="block hover:bg-gray-700 px-3 py-3">{{ $search }}</a>
            </li>
            <li class="border-b border-gray-700">
                <a href="#" class="block hover:bg-gray-700 px-3 py-3">Avengers</a>
            </li>
            <li class="border-b border-gray-700">
                <a href="#" class="block hover:bg-gray-700 px-3 py-3">Avengers</a>
            </li>
        </ul>
    </div>
</div>

I have included Livewire in my main.blade file

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Movie App</title>

    <link rel="stylesheet" href="{{ URL::asset('/css/main.css') }}">
    <livewire:styles />
</head>

And this before the end of the body

<livewire:scripts />

Now when I write something in my searchbox, it should have updated as i write, but it's not updating instead showing "hello there" - initial value of the $search variable.

P.S : This is what its showing in my browser. For some reason livewire.js is getting error. How to fix this?


回答1:


I followed the advise by @Kamlesh Paul and it worked.

you need to setup livewire base url

in config/livewire.php

'asset_url'  =>  env('APP_URL', 'http://localhost'),

then in .env

APP_URL=your_app_url


来源:https://stackoverflow.com/questions/65051509/why-laravel-livewire-wiremodel-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!