feat: useDelay doing

This commit is contained in:
FairyEver 2021-12-16 22:13:33 +08:00
parent 49b73744bb
commit 70ffa9d285
1 changed files with 15 additions and 0 deletions

15
d2/use/delay.js Normal file
View File

@ -0,0 +1,15 @@
import { ref, computed, watch } from 'vue'
import { throttle } from 'lodash-es'
export function useDelay (defaultValue, wait = 1000) {
const valueInside = ref(defaultValue)
const valueExternal = ref(defaultValue)
const updateValueExternal = throttle(() => {}, wait)
const value = computed({
get: () => valueExternal.value,
set: newValue => { valueInside.value = newValue }
})
return value
}