最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Pagination Issue with Array in Livewire 3.x :Uncaught Could not find Livewire component in DOM tree - Stack Overflo

programmeradmin1浏览0评论

I'm working with Livewire 3 and facing an issue when paginating a user list. I’ve applied the WithPagination trait and set the pagination theme to Bootstrap, but the pagination links don’t update the data unless I manually refresh the page. If I remove @extends('layouts.app') it works fine, in the browser console -

Uncaught Could not find Livewire component in DOM tree

I tried to remove the Bootstrap theme and it didn't help out -

class UsersList extends Component
{
  use WithPagination;
  // protected $paginationTheme = 'bootstrap';
  public $list;

  public function render()
  {
      $list = User::paginate(10);
      return view('livewire.usersList', ['list' => $list ]);
  }
} 

Thank you!

I'm working with Livewire 3 and facing an issue when paginating a user list. I’ve applied the WithPagination trait and set the pagination theme to Bootstrap, but the pagination links don’t update the data unless I manually refresh the page. If I remove @extends('layouts.app') it works fine, in the browser console -

Uncaught Could not find Livewire component in DOM tree

I tried to remove the Bootstrap theme and it didn't help out -

class UsersList extends Component
{
  use WithPagination;
  // protected $paginationTheme = 'bootstrap';
  public $list;

  public function render()
  {
      $list = User::paginate(10);
      return view('livewire.usersList', ['list' => $list ]);
  }
} 

Thank you!

Share Improve this question edited Feb 6 at 13:14 skdishansachin 7044 silver badges21 bronze badges asked Feb 5 at 16:06 Rezki HaniRezki Hani 1
Add a comment  | 

1 Answer 1

Reset to default 0

i guess this is happened because when the Livewire component is not properly included in the DOM after a re-render, especially when using pagination with an array

Try this approach

 <?php
use Livewire\WithPagination;

class UsersList extends Component{

use WithPagination;
public $list ;


    use WithPagination;

    public function render()
    {
        $data = Model::paginate(10); // Correct way to paginate
        return view('livewire.usersList', ['list' => $list ]);
    }
} ?>

Add key() to the Component

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div wire:key="unique-key-{{ $loop->index }}">
        @foreach ($data as $item)
            <p>{{ $item->name }}</p>
        @endforeach
    
        {{ $data->links() }} <!-- Ensure you're using Laravel's pagination links -->
    </div>
</body>
</html>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论