本文介绍了为什么Laravel-livewire'wire:model'不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Laravel 8.
I am using Laravel 8.
我的Livewire控制器
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刀片
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>
我已经将Livewire包含在main.blade文件中
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>
在身体末端之前
<livewire:scripts />
现在,当我在搜索框中编写内容时,它应该已经在我编写时进行了更新,但是并没有进行更新,而是显示"hello there".-$ search变量的初始值.
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:这就是它在我的浏览器中显示的内容.由于某些原因,livewire.js出错.如何解决这个问题?
P.S :This is what its showing in my browser. For some reason livewire.js is getting error. How to fix this?
推荐答案
添加
@livewireStyles
<link rel="stylesheet"
href="{{ mix('css/app.css') }}">
和
<script src="{{ mix('js/app.js') }}"></script>
@livewireScripts
在您的主布局文件中,我认为应该可以使用
at your main layouts file, I think it should be worked
这篇关于为什么Laravel-livewire'wire:model'不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!