-
Infinite Scroll 구현 (더보기)Laravel/Inertia.js 2022. 6. 17. 11:17반응형SMALL
# What?
일반적인 페이징 방식이 아닌, 더보기를 누르는 방식
# How?
- 핵심은 replaceState로 url 파라미터를 초기화하는것.
-> 이렇게 안하면 page 파라미터가 url에 남아있어서 새로고침 시 3페이지부터 보이고 이럼
@ Test.vue
<template> <div class="btn-wrap" style="margin-top:40px;"> <a href="" class="blue-btn" @click.prevent="() => filter(true)">더보기</a> </div> </template> <script> components: {Link, Pagination}, data(){ return { initialUrl: this.$page.url, bids: this.$page.props.bids, form: this.$inertia.form({ page: 1, }), } }, methods:{ filter(loadMore = false){ if(loadMore){ if(this.form.page >= this.bids.meta.last_page) return false; this.form.page += 1; } this.form.get("/bids", { preserveScroll: true, preserveState: true, onSuccess: (page) => { if(loadMore){ window.history.replaceState({}, this.$page.title, this.initialUrl) return this.bids = { ...this.bids, data: [...this.bids.data, ...page.props.bids.data] }; } return this.bids = page.props.bids; } }); }, }, mounted() { } </script>
LIST'Laravel > Inertia.js' 카테고리의 다른 글
lang, translate, locale, 다국어, global 언어 지원하기(laravel + inertia.js + nuxt 버전 추가) (0) 2022.10.29 Root View 변경하는법 (루트 뷰, 레이아웃) (0) 2022.08.27 Inertia.js에서 AOS 사용하는법 (0) 2022.05.21 Inertia.js 외부링크로 redirect하는법(결제 요청 시 필요) (0) 2022.05.13 검색 필터 및 더보기 구현(#Filter #Search #LoadMore) (0) 2021.11.16