首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当有自定义链接时,Livewire分页无法工作

当有自定义链接时,Livewire分页无法工作
EN

Stack Overflow用户
提问于 2022-11-16 04:38:36
回答 1查看 18关注 0票数 0

当我尝试在不传递{{ $dish->link() }}参数的情况下分页时,它工作得非常好。

但是,当我试图为它添加自定义模板(例如('paginate:bootstrap-5') )时,它不再正常工作(我的意思是,当我切换到其他页面时,页面刷新)。

这是我的直播模板

代码语言:javascript
复制
<div id="recipe_list" class="d-flex justify-content-start flex-wrap">
    @foreach ($dish as $recipe)
        <div id="recipe_item" class="me-4 mt-2 p-2 d-flex flex-column text-center" :wire:key="$recipe->id">
            <img src="{{asset('img/profile_picture.jpg')}}" alt="">
            <p class="text-break font mt-2 fw-bold" id="ingredient_count">{{$recipe->ingredient_count}} Ingredients</p>
            <p class="text-break font" id="recipe_name">{{$recipe->dish_name}}</p>
            <button class="btn btn-primary text-white font">View</button>
        </div>
    @endforeach

    <div id="pagination" class="d-block d-flex justify-content-center pt-2 mt-5">
        {{ $dish->links() }}
    </div>
</div>

我的活电线控制器

代码语言:javascript
复制
use Livewire\Component;
use Illuminate\Support\Str;
use App\Models\User;
use App\Models\Dish;
use App\Models\Ingredient;
use App\Models\DishImage;
use Livewire\WithPagination;

class Pagination extends Component
{
    use WithPagination;

    protected $paginationTheme = 'bootstrap';

    public function getQueryString()
    {
        return [];
    }

    public function render()
    {
        $dish = Dish::paginate(12);
        
        foreach ($dish->items() as $key => $value) {

            $dish[$key]->ingredient_count = Ingredient::where('dish_id', $value->id)->count(); 
        }   
        return view('livewire.pagination', [
            'dish' => $dish,
        ]);
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-16 11:49:48

另外,我已经通过查看livewire文档https://laravel-livewire.com/docs/1.x/pagination“#使用自定义分页视图”来解决这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74455247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档