Browse Source

添加图标缓存

pull/1/head
wanggang 1 year ago
parent
commit
0737746148
  1. 10
      docs/demo/src/WTA/wwwroot/components/icon/index.js

10
docs/demo/src/WTA/wwwroot/components/icon/index.js

@ -1,5 +1,6 @@
import html from "html";
import { onMounted, ref } from "vue";
import { useAppStore } from "../../store/index.js";
export default {
template: html`<template v-if="name.indexOf('ep-')===0">
@ -19,10 +20,19 @@ export default {
if (!props.name.startsWith("ep-")) {
try {
const url = `./assets/icons/${props.name}.svg`;
navigator.locks.request(url, async () => {
const appStore = useAppStore();
if (appStore.cache.has(url)) {
svg.value = appStore.cache.get(url);
} else {
const response = await fetch(url);
if (response.ok && response.status === 200) {
svg.value = await response.text();
appStore.cache.set(url, svg.value);
}
}
});
c;
} catch (error) {
console.log(error);
if (!svg.value) {

Loading…
Cancel
Save