diff --git a/src/hooks/useComputed.ts b/src/hooks/useComputed.ts new file mode 100644 index 0000000..c95735a --- /dev/null +++ b/src/hooks/useComputed.ts @@ -0,0 +1,16 @@ +import { computed } from "vue" + +const useComputed = (fn: Function) => { + const map = new Map() + return (...args: any[]) => { + const key = JSON.stringify(args) + if (map.has(key)) { + return map.get(key) + } + const comput = computed(() => fn(...args)) + map.set(key, comput) + return comput + } +} + +export default useComputed