我正在尝试学习使用livewire。所以我从文档和截屏开始。我正在使用带有 Livewire 脚手架的 Jetstream 构建一个 Laravel 项目。问题似乎是控制器没有将变量传递给刀片模板。
我之前做了一个测试项目,只使用 Laravel 8,修改了welcome.blade.php
模板并需要 Composer 的 Livewire。它工作得很好。
重现步骤:创建一个 Laravel 8.x jetstream 项目并使用我的代码
这是我的代码:
在:App\Http\Livewire\AddPost.php:
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class AddPost extends Component
{
public $title = "Blank";
public $content = "Such empty here";
public function render()
{
return view('livewire.add-post');
}
}
在:资源/视图/add-post.blade.php
<html>
<head>
@livewireStyles
</head>
<body>
@livewire('add-post')
@livewireScripts
</body>
</html>
在:资源\视图\livewire\add-post.blade.php
<div>
Title: {{ $title }}
<br>
Content: {{ $content }}
</div>