18 lines
320 B
TypeScript
18 lines
320 B
TypeScript
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
|