Laravel Livewire component not refreshing/reloading automatically after refreshing it

主宰稳场 提交于 2020-05-15 02:08:12

问题


So, I'm currently using Laravel Livewire in one of my projects. But when I try emit an event from one component to another component by magic mathod $refresh , its refreshing (got the dom in xhr request ) the total component but the Front end is not updating realtime.

ProductReviewForm.php Component

  public function save()
    {
        //some functionalities .... 


        $this->emit('reviewSectionRefresh');


    }

ProductReviewSection.php Component

 protected $listeners = [
        'reviewSectionRefresh' => '$refresh',
    ];

    public function render()
    {
        $this->review_lists = ProductReview::orderBy('id', 'DESC')->get();

        return view('livewire.desktop.product-review-section');
    }

So I want to emit the reviewSectionRefresh event to be emitted whenever I call save() function from First component, That should be listened by $listeners from other component. This is working fine. also in xhr I'm getting the refreshed dom but the component in frontend is not updating. Hoping anyone working with Livewire may help with that.


回答1:


So it seems I've write my component blade view in wrong way.

all things on refreshed component should be wrapped in one div element like this:

<div> 
{{-- Anything you want to do --}}

</div>  

previously my blade file was like. Which is Wrong

<div class=""> 
 {{ -- some dom elements -- }}
</div>

<div class=""> 
{{ -- some other dom elements -- }}
</div>

but that should be like.

<div>
    <div class=""> 
       {{ -- some dom elements -- }}
    </div>

    <div class=""> 
    {{ -- some other dom elements -- }}
    </div>
</div>

So Whatever you write, that should be inside ONE PARENT DIV ELEMENT



来源:https://stackoverflow.com/questions/60395647/laravel-livewire-component-not-refreshing-reloading-automatically-after-refreshi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!