【发布时间】:2021-05-01 16:36:27
【问题描述】:
我是 LiveWire 的新手,正在尝试使用 Laravel、jetstream 和 livewire 构建简单的应用程序
我的应用程序从数据库中获取数据并显示在分页表中。 一切正常,但问题是当我点击任何页面时,我得到了 URI '?page=2'
我不想在 Url 中看到这个 URI 我的刀片也很简单
<x-app-layout>
<x-slot name="header">
</x-slot>
<div class="py-2">
<div class="mx-auto sm:px-2 lg:px-2">
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
<div class="flex flex-wrap">
<livewire:item />
</div>
</div>
</div>
</div>
</x-app-layout>
和 livewire:item
<table class="table-auto w-full">
<thead>
<tr>
<th class="px-4 py-2">
<div class="flex items-center">
<button>Image</button>
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('sku')">SKU</button>
<x-sort-icon sortField="sku" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('title')">Title</button>
<x-sort-icon sortField="title" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('avg_pprice')">Price</button>
<x-sort-icon sortField="avg_pprice" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('stock')">Stock</button>
<x-sort-icon sortField="stock" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('selling_price')">Sale Price</button>
<x-sort-icon sortField="selling_price" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th class="px-4 py-2">
Actions
</th>
</tr>
</thead>
<tbody>
@foreach($items as $item)
<tr>
<td class="border px-4 py-2"><img class="w-20" src='{{ $item->image}}'></td>
<td class="border px-4 py-2">{{ $item->title}}</td>
<td class="border px-4 py-2">{{ number_format($item->price, 2)}}</td>
</tr>
@endforeach
</tbody>
</table>
<div class="mt-4">
{{ $items->links() }}
</div>
livewire 控制器也是
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\item;
use Livewire\WithPagination;
class Items extends Component
{
use WithPagination;
public $perPage = 10;
public function render()
{
$items = Item::all();
$items = $items->paginate($this->perPage);
return view('livewire.items', [
'items' => $items,
]);
}
}
【问题讨论】:
-
您的组件看起来不错。你能更新你的
livewire:item查看它现在的样子吗? -
我的视图文件现在看起来像这样
...
{{ $items->links( ) }} -
我认为 LiveWire 正在添加查询字符串
-
页面链接的url是什么?
-
Url 可以仅查询字符串,例如 ?page=2 ,有没有办法可以删除它以保持 URL 干净
标签: php laravel laravel-livewire jetstream