请教一下关于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 为技术新手提供服务
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 2

public $content; 这个你确定能找到这个变量吗使用 $this 的方式

2年前 评论
running8

livewire 组件视图,最外层必须有一对 <div>...</div>

这样就隔离了

2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!