From 3a508934d828a5234636c8cddb211147f38fa01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=B6=E8=BF=9C=E6=96=B9?= Date: Wed, 12 Apr 2023 21:16:41 +0800 Subject: [PATCH] fix(useSortable): order of dom and array is different (#2926) --- packages/integrations/useSortable/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/integrations/useSortable/index.ts b/packages/integrations/useSortable/index.ts index b494dd31ebf..da8f01856ba 100644 --- a/packages/integrations/useSortable/index.ts +++ b/packages/integrations/useSortable/index.ts @@ -1,6 +1,7 @@ import { defaultDocument, resolveUnref, tryOnMounted, tryOnScopeDispose, unrefElement } from '@vueuse/core' import type { ConfigurableDocument, MaybeComputedRef } from '@vueuse/core' import Sortable, { type Options } from 'sortablejs' +import { nextTick } from 'vue-demi' export interface UseSortableReturn { /** @@ -62,6 +63,8 @@ export function moveArrayElement( to: number, ): void { const array = resolveUnref(list) - if (to >= 0 && to < array.length) - array.splice(to, 0, array.splice(from, 1)[0]) + if (to >= 0 && to < array.length) { + const element = array.splice(from, 1)[0] + nextTick(() => array.splice(to, 0, element)) + } }