Skip to content

useSortable

Wrapper for sortable

Install

npm install sortablejs@^1

npm install @vueuse/integrations

Usage

js

import { useSortable } from '@vueuse/integrations/useSortable'

// const el = ref<HTMLElement | null>(null)  ts 定义

/**
 * @ref HTML element
 * @list real list
 * @animation ms, animation speed moving items when sorting, `0` — without animation
 * @ghostClass Class name for the drop placeholder
 * @chosenClass Class name for the chosen item
 */
const option = useSortable(ref, list, {
  animation: 150,
  ghostClass: "sortable-ghost",
  chosenClass: "sortable-chosen",
  onEnd(() => {
    // Element dragging ended
  })
});

// You can use the option method to set and get the option of Sortable
option('animation', 200) // set
option('animation') // 200

For more infomation on what options can be passed, see:

2025( )
今日 8.33%
本周 42.86%
本月 48.39%
本年 4.11%
Powered by Snowinlu | Copyright © 2024- | MIT License