我在试着学习如何使用livewire。所以我从文档和录像带开始。我使用Jetstream和Livewire脚手架构建了一个Laravel项目。问题似乎是控制器没有将变量传递给刀片模板。
我之前做了一个测试项目,只使用Laravel 8,修改了welcome.blade.php
模板,并要求Livewire by composer。而且它工作得很好。
重现步骤:创建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');
}
}
在: resources/views/add-post.blade.php中
<html>
<head>
@livewireStyles
</head>
<body>
@livewire('add-post')
@livewireScripts
</body>
</html>
位于: resources\views\livewire\add-post.blade.php
<div>
Title: {{ $title }}
<br>
Content: {{ $content }}
</div>
发布于 2020-12-01 02:36:35
尝尝这个
public function render()
{
return view('livewire.add-post', [
'title' => $this->title,
'content' => $this->content
});
}
或
@livewire('add-post', ['title' => 'lorem ipsum', '' => 'content'])
或者使用这个函数,它就像一个构造函数()。
public function mount() {
$this->title = 'lorem ipsum';
$this->content = 'content';
}
发布于 2021-01-12 14:23:49
在app.blade.php中试用:{{$slot}}
<html>
<head>
@livewireStyles
</head>
<body>
{{ $slot }} <<<<<<<--------------
@livewireScripts
</body>
</html>
发布于 2021-03-27 13:06:11
你可以使用这个
public $title;
public $content;
public function mount(){
$this->title= "Blank";
$this->content= "Such empty here";
}
https://stackoverflow.com/questions/63935291
复制相似问题