如何使用Jetstream在Laravel 8中添加新的Livewire组件时解决RootTagMissingFromViewException错误

时间:2020-09-26 21:31:43

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

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

错误:

RootTagMissingFromViewException

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>

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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