因此,当我尝试对我的数据进行分页并通过 livewire 组件将其发送到视图时出现此错误。
我正在尝试使用 Laravel 中的分页获取所有帖子并以每页最多 5 个帖子显示。
Livewire 版本:2.3.1
Laravel 版本:8.13.0
错误:
Livewire\Exceptions\PublicPropertyTypeNotAllowedException
Livewire component's [user-posts] public property [posts] must be of type: [numeric, string, array, null,
or boolean]. Only protected or private properties can be set as other types because JavaScript doesn't
need to access them.
Run Code Online (Sandbox Code Playgroud)
我的组件:
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Post;
use Livewire\WithPagination;
class UserPosts extends Component
{
use WithPagination;
public $posts;
public $type;
protected $listeners = ['refreshPosts'];
public function delete($postId)
{
$post = Post::find($postId); …Run Code Online (Sandbox Code Playgroud)