【发布时间】:2019-09-09 12:06:09
【问题描述】:
我有一个这样分页的模型:
$reserve = PropertyCalendar::paginate(1);
return new ReserveResource($reserve);
我还创建了一个响应资源的 API,在 Vue 组件中我将使用axios.get 调用它。
public function toArray($request)
{
return parent::toArray($request);
}
这是 API 响应:
{
"current_page": 1,
"data": [
{
"id": 1,
"property_id": 1,
"user_id": 1,
"payable_price": 11,
"reserve_start": "2019-03-30 00:00:00",
"reserve_end": "2019-04-01 00:00:00",
"created_at":null,
"updated_at":null
}
],
"first_page_url": "http:\/\/localhost:8000\/api\/reserve?page=1",
"from": 1,
"last_page": 2,
"last_page_url": "http:\/\/localhost:8000\/api\/reserve?page=2",
"next_page_url": "http:\/\/localhost:8000\/api\/reserve?page=2",
"path": "http:\/\/localhost:8000\/api\/reserve",
"per_page": 1,
"prev_page_url": null,
"to": 1,
"total": 2
}
现在我想知道如何为它进行分页,我无法像在 Vue 组件中那样使用传统的 Laravel 分页。
loadReserves() {
axios.get("../api/reserve", {
params: {
commentId: this.comment_id
}
}).then((response) => (this.comments = response.data.data));
},
现在我正在显示数据,但我想像 API 中的那样对其进行分页。
【问题讨论】:
-
到目前为止你有什么尝试?
-
您是否在使用任何 UI 库,例如 vuetify、element-ui 或 buefy?
-
@CloudSohJunFu 没有什么我什么都不用