api - 如何创建 vuejs unsplash 分页?
问题描述
我正在尝试使用 vuejs 创建图库 unspalash API。
我完成了大部分工作,但堆叠在分页中。我看到有一个链接可以提供所有页面信息,但它是字符串格式
<https://api.unsplash.com/photos?order_by=popular&page=1&per_page=4>; rel="first", <https://api.unsplash.com/photos?order_by=popular&page=1&per_page=4>; rel="prev", <https://api.unsplash.com/photos?order_by=popular&page=45021&per_page=4>; rel="last", <https://api.unsplash.com/photos?order_by=popular&page=3&per_page=4>; rel="next"
数据为字符串格式。我如何在 vue 分页中显示它;我不知道。
我需要这个字符串中的 4 个按钮 First、Next、Previous、Last。
提前致谢。
解决方案
好的,我找到了解决方案。this.pagination = response.headers.link.split(", "); 所以它将从字符串创建数组。现在您可以循环该数组并使用 rel=name 从中找到单个链接
<span class="red" v-for="pagi in pagination" v-bind:key="pagi.id">
<button
v-if="pagi.includes('first')"
class="bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow mr-3"
v-on:click="fetchPaginateNews(pagi.split('; ')[0])"
>First</button>
<button
v-if="pagi.includes('next')"
class="bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow mr-3"
v-on:click="fetchPaginateNews(pagi.split('; ')[0])"
>Next</button>
<button
v-if="pagi.includes('prev')"
class="bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow mr-3"
v-on:click="fetchPaginateNews(pagi.split('; ')[0])"
>Prevous</button>
<button
v-if="pagi.includes('last')"
class="bg-white hover:bg-gray-100 text-gray-800 font-semibold py-2 px-4 border border-gray-400 rounded shadow mr-3"
v-on:click="fetchPaginateNews(pagi.split('; ')[0])"
>Last</button>
推荐阅读
- json - 将响应转换为 Flux 忽略响应 Json 的某些字段
- docker-compose - Bitnami Apache、MariaDB、PrestaShop 和 PHPMyAdmin 的 docker-compose.yml 无法正常工作
- jquery - 按类查找下一个元素(可能不是兄弟)jquery
- python - 切片数组时“TypeError:'NoneType'对象不可下标”
- amazon-web-services - 限制文件上传到存储桶根目录(预签名表单)
- php - 如何在 PHP 中访问 SharePoint 上的共享文件?
- angular - Angular 将 FormData 传递给 WebAPI。获取空值
- vue.js - 使用 set 存储唯一值但是如果我的数组中有更多数据怎么办
- python - 在机器人框架中找不到名为“foo”的关键字
- javascript - 控制台说 Math.Floor 不是函数。我怎样才能解决这个问题