请教一下关于livewire组件嵌套出现的问题
需求是使用livewire做一个留言提交的功能。
我定义了两个组件:
blog-comments
留言板整体的组件comment-create
创建留言的组件
blog-comments组件内引用了comment-create组件
blog-comments.blade.php
<livewire:comment-create />
blog-create组件的视图模板
<form wire:submit.prevent="createComment">
<textarea wire:model.lazy="content" id="comment-content">
</textarea>
<button type="submit">发送</button>
</form>
blog-create组件的控制器代码
class CommentCreate extends Component
{
public $content;
public function createComment()
{
dd($this->content);
}
public function render()
{
return view('livewire.comment-create');
}
}
然后提交留言,提示错误
Property [$content] not found on component: [blog-comments]
请问是什么原因哈?
乌鸦嘴社区 wyz.xyz 来玩。
public $content; 这个你确定能找到这个变量吗使用 $this 的方式
livewire 组件视图,最外层必须有一对
<div>...</div>
这样就隔离了