useComputed
This commit is contained in:
1 parent
61041d4ae4
commit
dff63144ea
1 file changed
+17
@@ -0,0 +1,17 @@
|
||||
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
|
||||
Reference in new issue
Block a user