Skip to content

Commit

Permalink
fix(useOffsetPagination): don't mutate props when it's readonly (#3581)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-wu committed Dec 4, 2023
1 parent 7e2da58 commit 4dacec8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/core/useOffsetPagination/index.ts
@@ -1,5 +1,5 @@
import type { ComputedRef, Ref, UnwrapNestedRefs } from 'vue-demi'
import { computed, isRef, reactive, watch } from 'vue-demi'
import { computed, isReadonly, isRef, reactive, watch } from 'vue-demi'
import { noop, syncRef, toValue } from '@vueuse/shared'
import type { MaybeRef, MaybeRefOrGetter } from '@vueuse/shared'
import { useClamp } from '../../math/useClamp'
Expand Down Expand Up @@ -74,11 +74,17 @@ export function useOffsetPagination(options: UseOffsetPaginationOptions): UseOff
const isFirstPage = computed(() => currentPage.value === 1)
const isLastPage = computed(() => currentPage.value === pageCount.value)

if (isRef(page))
syncRef(page, currentPage)
if (isRef(page)) {
syncRef(page, currentPage, {
direction: isReadonly(page) ? 'ltr' : 'both',
})
}

if (isRef(pageSize))
syncRef(pageSize, currentPageSize)
if (isRef(pageSize)) {
syncRef(pageSize, currentPageSize, {
direction: isReadonly(pageSize) ? 'ltr' : 'both',
})
}

function prev() {
currentPage.value--
Expand Down

0 comments on commit 4dacec8

Please sign in to comment.