【问题标题】:How to resolve RootTagMissingFromViewException error while adding new Livewire component in Laravel 8 with Jetstream使用 Jetstream 在 Laravel 8 中添加新 Livewire 组件时如何解决 RootTagMissingFromViewException 错误
【发布时间】:2021-01-12 21:16:03
【问题描述】:

我正在尝试向 Laravel 8 Jetstream 添加一个新的 Livewire 组件,但看起来我做错了什么并收到以下错误。

错误:

Livewire\Exceptions\RootTagMissingFromViewException
Livewire encountered a missing root tag when trying to render a component. When rendering a Blade view, make sure it contains a root HTML tag

路线:

// web.php
Route::middleware('auth')->group(function() {
    Route::get('/newEmployee', NewEmployee::class);
});

控制器:


// app/Http/Livewire/NewEmployee.php

namespace App\Http\Livewire;

use Livewire\Component;

class NewEmployee extends Component
{
    public function render()
    {
        return view('livewire.new-employee')->layout('layouts.app')->name('NewEmployee');
    }
}

查看:

<!-- resources/views/livewire/new-employee.blade.php  -->
<div>
    <div class="max-w-7xl mx-auto py-10 sm:px-6 lg:px-8">
            <h1> New Wmployee </h1>
    </div>
</div>

【问题讨论】:

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


    【解决方案1】:

    您需要在 livewire BLADE 文件中添加任何 HTML 标签。 LiveWire 在 BLADE 文件中需要 HTML TAG。因此,在 LIVEWIRE BLADE 中添加简单的 TEST PAGE。问题应该得到解决。

    【讨论】:

      【解决方案2】:

      不会(命名)方法。请定义:

      return view('livewire.new-employee')->layout('layouts.app');
      

      【讨论】:

      • 请详细说明你的答案。
      • 对我来说,这很有效:return view('livewire.new-employee')->extends('layouts.app');
      猜你喜欢
      • 2021-10-13
      • 2021-04-07
      • 2020-08-10
      • 2021-06-18
      • 2021-03-05
      • 2021-01-21
      • 2021-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多