Skip to content

Commit 8852906

Browse files
committed
index reset
1 parent cbba813 commit 8852906

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/runtime/composables/useLaravelIndex.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,22 @@ export function useLaravelIndex<T extends object>(
323323
}
324324
)
325325

326+
const reset = () => {
327+
state.value.items = []
328+
state.value.error = null
329+
state.value.loading = false
330+
state.value.meta = undefined
331+
state.value.page = undefined
332+
state.value.perPage = options?.perPage || 10
333+
state.value.syncUrl = options?.syncUrl ?? true
334+
state.value.sort = options?.sort || ''
335+
state.value.search = undefined
336+
state.value.filter = {}
337+
state.value.__updated = new Date()
338+
state.value.__hash = undefined
339+
state.value.__ssr = options?.ssr ?? false
340+
}
341+
326342
return {
327343
...toRefs(state.value),
328344
state,
@@ -341,5 +357,6 @@ export function useLaravelIndex<T extends object>(
341357
loadAll,
342358
loadMore,
343359
mutateStateItem,
360+
reset,
344361
}
345362
}

src/runtime/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export type LaravelIndex<T> = ToRefs<LaravelIndexState<T>> & {
6969
loadAll: () => Promise<void>
7070
loadMore: () => void
7171
mutateStateItem: (id: string | number, data: Partial<T>) => void
72+
reset: () => void
7273
}
7374

7475
export type FilterOperatorOption =

0 commit comments

Comments
 (0)