Vben
2021-02-25 8a9ca498d70a0a4f66c073fe869fc6d8a3e79a55
提交 | 用户 | age
116a1f 1 import { nextTick, unref } from 'vue';
V 2 import type { Ref } from 'vue';
8a9ca4 3 import type { Options } from 'sortablejs';
116a1f 4
8a9ca4 5 export function useSortable(el: HTMLElement | Ref<HTMLElement>, options?: Options) {
116a1f 6   function initSortable() {
8a9ca4 7     nextTick(async () => {
116a1f 8       if (!el) return;
8a9ca4 9
V 10       const Sortable = (await import('sortablejs')).default;
116a1f 11       Sortable.create(unref(el), {
V 12         animation: 500,
13         delay: 400,
14         delayOnTouchOnly: true,
15         ...options,
16       });
17     });
18   }
19
20   return { initSortable };
21 }