方法 App\Livewire\Post\Comment::emit 不存在

问题描述 投票:0回答:1

我在 Laravel 中使用 Livewire 框架,我创建了一个评论功能,我希望当我评论时,屏幕会通过我使用 JavaScript 插入的 ID 自动滚动到评论,但当我发表评论时,它应该自动向下滚动,但相反它出现 错误消息“方法 App\Livewire\Post\Comment::emit 不存在。”

请帮助我

 public function store()
    {
        $this->validate(["body" => "required"]);
        $comment = ModelsComment::create([
            'user_id' => Auth::user()->id,
            "article_id" => $this->article->id,
            "body" => $this->body
        ]);

        if($comment){
            $this->emit('commentStored', $comment->id);
            $this->body = null; 
        } else {
            session()->flash('danger', 'Komentar gagal Ditambahkan!!');
            return redirect()->route('data', $this->article->slug);
        }
    }

$this->emit('commentStored', $comment->id);

我在任何网站上进行了搜索,但没有人讨论此错误

javascript php laravel laravel-5 laravel-livewire
1个回答
0
投票

我想您正在使用 Livewire 3。
在此版本中,emit()dispatchBrowserEvent()已统一为方法dispatch()

© www.soinside.com 2019 - 2024. All rights reserved.