fah*_*152 14 php laravel laravel-livewire
所以,我目前在我的一个项目中使用Laravel Livewire。但是,当我尝试通过 magic mathod 从一个组件向另一个组件发出事件时$refresh,它刷新了(在 xhr 请求中获得了 dom)整个组件,但前端没有实时更新。
ProductReviewForm.php 成分:
public function save()
{
//some functionalities ....
$this->emit('reviewSectionRefresh');
}
Run Code Online (Sandbox Code Playgroud)
ProductReviewSection.php 成分:
protected $listeners = [
'reviewSectionRefresh' => '$refresh',
];
public function render()
{
$this->review_lists = ProductReview::orderBy('id', 'DESC')->get();
return view('livewire.desktop.product-review-section');
}
Run Code Online (Sandbox Code Playgroud)
所以我想reviewSectionRefresh在我save()从第一个组件调用函数时发出要发出的事件,这应该被$listeners其他组件监听。这工作正常。同样在 xhr 中,我得到了刷新的 dom,但前端的组件没有更新。希望任何与 Livewire 合作的人都可以对此有所帮助。
fah*_*152 39
所以看起来我以错误的方式编写了我的组件刀片视图。
刷新组件上的所有内容都应该像这样包装在一个 div 元素中:
<div>
{{-- Anything you want to do --}}
</div>
Run Code Online (Sandbox Code Playgroud)
以前我的刀片文件就像。哪个是错的
<div class="">
{{ -- some dom elements -- }}
</div>
<div class="">
{{ -- some other dom elements -- }}
</div>
Run Code Online (Sandbox Code Playgroud)
但应该是这样的。
<div>
<div class="">
{{ -- some dom elements -- }}
</div>
<div class="">
{{ -- some other dom elements -- }}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
所以无论你写什么,都应该在 ONE Parent DIV ELEMENT 中