【问题标题】:Laravel 8 - wire:model on input not workingLaravel 8 - 线:输入上的模型不起作用
【发布时间】:2021-03-01 04:57:34
【问题描述】:

我正在尝试使用 livewire,但无法正常工作。

我有一条路线:

Route::middleware(['auth:sanctum', 'verified'])
    ->get('/nuevoturno', NuevoTurno::class)
    ->name('nuevoturno');

NuevoTurno.php 包含:

namespace App\Http\Livewire;

use App\Models\FormatoTurno;
use Livewire\Component;

class NuevoTurno extends Component
{

    public $qFecha = '2020-11-17';

    public function render()
    {
        return view('livewire.nuevo-turno',[
            'formatoTurno' => FormatoTurno::First()
        ]);
    }

}

livewire 视图:

@section('header', 'Nuevo Turno')

@section('content')
{{ $qFecha }}
<input type="text" value="{{ $qFecha }}">
<div>
    <br>
    {{-- A good traveler has no fixed plans and is not intent upon arriving. --}}
    {{ $formatoTurno->Distancia_Entre_Turnos }}
    {{ $formatoTurno->Hora_Inicio }}
    {{ $formatoTurno->Hora_Fin }}
</div>
@endsection

{{ $qFecha }} 正在显示,但输入未填充

那么..发生了什么事?

编辑: 我将@section('content') 更改为 app.blade.php 并将@yield('content') 更改为 {{ $slot }} 现在它出现了:

< wire:id="BCEos1ECXtGL114CYnTn" wire:initial-data="{"fingerprint":{"id":"BCEos1ECXtGL114CYnTn","name":"nuevo-turno","locale":"es"},"effects":{"listeners":[]},"serverMemo":{"children":[],"errors":[],"htmlHash":"850cd1b2","data":{"qFecha":"2020-11-17"},"dataMeta":[],"checksum":"3cb32d8a817d51f7ff71a9ebeb184da10fb421dc1eb00e1ddd53a4ab30dcefb7"}}"!doctype html>

【问题讨论】:

  • Livewire 现在默认假定您使用基于插槽/组件的方法,而不是部分和扩展。也就是说,来自文档laravel-livewire.com/docs/2.x/upgrading:“Livewire 默认使用相同的布局文件,但是,它现在希望您在布局中使用新的 Blade 组件 $slot 语法。”。
  • 另外,请注意,您的 Livewire 组件应该只有 一个 单个根元素。您可以将整个组件包装在 &lt;div&gt; 中。请参阅“返回刀片视图”下的laravel-livewire.com/docs/2.x/rendering-components,它会说“确保您的刀片视图只有一个根元素。”
  • 如果您有答案,请发布答案。不要在你的问题中编辑它

标签: php laravel eloquent laravel-8 laravel-livewire


【解决方案1】:

[解决方案] 我将 app.blade 格式从 @yield() 更改为 {{ $slot }}。 还更改了 livewire 组件 nuevo-turno.blade:

<x-slot name="header">
    Nuevo Turno
</x-slot>

<div>
    {{ $qFecha }}
    <input type="text" value="{{ $qFecha }}">
    <div>
        <br>
        {{-- A good traveler has no fixed plans and is not intent upon arriving. --}}
        {{ $formatoTurno->Distancia_Entre_Turnos }}
        {{ $formatoTurno->Hora_Inicio }}
        {{ $formatoTurno->Hora_Fin }}
    </div>
</div>

现在它可以工作了。 谢谢大家的回答!

【讨论】:

    猜你喜欢
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-13
    • 2021-03-11
    • 2020-10-01
    • 2021-03-13
    • 2017-10-16
    相关资源
    最近更新 更多