小程序初始提交
This commit is contained in:
28
cool-unix/cool/hooks/cache.ts
Normal file
28
cool-unix/cool/hooks/cache.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { reactive, watch } from "vue";
|
||||
import { isDark } from "../theme";
|
||||
|
||||
type CacheData = {
|
||||
key: number;
|
||||
};
|
||||
|
||||
type UseCache = {
|
||||
cache: CacheData;
|
||||
};
|
||||
|
||||
export const useCache = (source: () => any[]): UseCache => {
|
||||
const cache = reactive<CacheData>({
|
||||
key: 0
|
||||
});
|
||||
|
||||
watch(source, () => {
|
||||
cache.key++;
|
||||
});
|
||||
|
||||
watch(isDark, () => {
|
||||
cache.key++;
|
||||
});
|
||||
|
||||
return {
|
||||
cache
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user