useStaticUrl.ts 381 B

1234567891011121314151617
  1. import {api} from '@/store/sync'
  2. import {Ref, ref} from "vue";
  3. const cache = new Map<string, Ref<string>>()
  4. export const useStaticUrl = (url) => {
  5. if (cache.has(url)) {
  6. return cache.get(url);
  7. } else {
  8. const realUrl = ref<string>()
  9. api.getFile(url)
  10. .then(data => {
  11. realUrl.value = data
  12. cache.set(url, realUrl)
  13. })
  14. return realUrl
  15. }
  16. }