コンテンツへスキップ

useCycleList

カテゴリ
エクスポートサイズ
463 B
最終更新日
先週

アイテムのリストを順に切り替えます。

Vue Schoolのこの無料ビデオレッスンで、useCycleListを使用して画像カルーセルを作成する方法を学びましょう!

デモ

使い方

ts
import { useCycleList } from '@vueuse/core'

const { state, next, prev, go } = useCycleList([
  'Dog',
  'Cat',
  'Lizard',
  'Shark',
  'Whale',
  'Dolphin',
  'Octopus',
  'Seal',
])

console.log(state.value) // 'Dog'

prev()

console.log(state.value) // 'Seal'

go(3)

console.log(state.value) // 'Shark'

型宣言

typescript
export interface UseCycleListOptions<T> {
  /**
   * The initial value of the state.
   * A ref can be provided to reuse.
   */
  initialValue?: MaybeRef<T>
  /**
   * The default index when
   */
  fallbackIndex?: number
  /**
   * Custom function to get the index of the current value.
   */
  getIndexOf?: (value: T, list: T[]) => number
}
/**
 * Cycle through a list of items
 *
 * @see https://vueuse.dokyumento.jp/useCycleList
 */
export declare function useCycleList<T>(
  list: MaybeRefOrGetter<T[]>,
  options?: UseCycleListOptions<T>,
): UseCycleListReturn<T>
export interface UseCycleListReturn<T> {
  state: Ref<T>
  index: Ref<number>
  next: (n?: number) => T
  prev: (n?: number) => T
  /**
   * Go to a specific index
   */
  go: (i: number) => T
}

ソース

ソースデモドキュメント

貢献者

Anthony Fu
Anthony Fu
Poet
xiaofan
Helio S. Junior
Waleed Khaled
Jelf
markthree
lsdsjy

変更履歴

v12.0.0-beta.1 2024/11/21
0a9ed - feat!: Vue 2のサポートを廃止、バンドルを最適化、クリーンアップ(#4349
v10.8.0 2024/02/20
2ae36 - feat: go関数を追加(#3615
v10.1.0 2023/04/22
659b2 - 修正: リストをrefで正しくラップするように修正 (#2988)
v10.0.0-beta.4 2023年4月13日
4d757 - feat(types)!: MaybeComputedRefMaybeRefOrGetter にリネーム
10e98 - feat(toRef)!: resolveReftoRef にリネーム
0a72b - feat(toValue): resolveUnreftoValue にリネーム
v10.0.0-beta.0 2023年3月14日
b65c2 - feat: リアクティブなリストの受け取りを許可 (#2864)

MITライセンスの下でリリースされています。