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

Loading…
Cancel
Save