diff --git a/packages/core/useVModel/index.ts b/packages/core/useVModel/index.ts index 3283637ec9d..f61c9959492 100644 --- a/packages/core/useVModel/index.ts +++ b/packages/core/useVModel/index.ts @@ -1,6 +1,6 @@ import { isDef } from '@vueuse/shared' import type { Ref, UnwrapRef, WritableComputedRef } from 'vue-demi' -import { computed, getCurrentInstance, isVue2, ref, watch } from 'vue-demi' +import { computed, getCurrentInstance, isVue2, nextTick, ref, watch } from 'vue-demi' import type { CloneFn } from '../useCloned' import { cloneFnJSON } from '../useCloned' @@ -127,16 +127,23 @@ export function useVModel

(initialValue!) + let isUpdating = false watch( () => props[key!], - v => (proxy as any).value = cloneFn(v) as UnwrapRef, + (v) => { + if (!isUpdating) { + isUpdating = true + ;(proxy as any).value = cloneFn(v) as UnwrapRef + nextTick(() => isUpdating = false) + } + }, ) watch( proxy, (v) => { - if (v !== props[key!] || deep) + if (!isUpdating && (v !== props[key!] || deep)) triggerEmit(v as P[K]) }, { deep },