Commit 0daca28362419911d642e4b3a5111e213eef49d9

Authored by vben
1 parent c911af4a

fix(keep-alive): fix the problem that the multi-level routing cache page is rend…

…ered multiple times #123
package.json
... ... @@ -22,7 +22,7 @@
22 22 },
23 23 "dependencies": {
24 24 "@iconify/iconify": "^2.0.0-rc.2",
25   - "@vueuse/core": "^4.0.0-rc.7",
  25 + "@vueuse/core": "^4.0.0-rc.8",
26 26 "ant-design-vue": "^2.0.0-rc.4",
27 27 "apexcharts": "^3.22.3",
28 28 "axios": "^0.21.0",
... ...
src/layouts/page/ParentView.vue
... ... @@ -23,6 +23,7 @@
23 23 import { useCache } from './useCache';
24 24  
25 25 export default defineComponent({
  26 + parentView: true,
26 27 setup() {
27 28 const { getCaches } = useCache(false);
28 29  
... ...
src/layouts/page/index.tsx
... ... @@ -12,7 +12,7 @@ import { useCache } from './useCache';
12 12 import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
13 13  
14 14 interface DefaultContext {
15   - Component: FunctionalComponent;
  15 + Component: FunctionalComponent & { type: { [key: string]: any } };
16 16 route: RouteLocation;
17 17 }
18 18  
... ... @@ -42,7 +42,11 @@ export default defineComponent({
42 42 ? 'fade-slide'
43 43 : null;
44 44  
45   - const renderComp = () => <Component key={route.fullPath} />;
  45 + // When the child element is the parentView, adding the key will cause the component to be executed multiple times. When it is not parentView, you need to add a key, because it needs to be compatible with the same route carrying different parameters
  46 + const isParentView = Component?.type.parentView;
  47 + const componentKey = isParentView ? {} : { key: route.fullPath };
  48 +
  49 + const renderComp = () => <Component {...componentKey} />;
46 50  
47 51 const PageContent = unref(openCache) ? (
48 52 <KeepAlive include={cacheTabs}>{renderComp()}</KeepAlive>
... ...
yarn.lock
... ... @@ -1757,18 +1757,18 @@
1757 1757 vscode-languageserver-textdocument "^1.0.1"
1758 1758 vscode-uri "^2.1.2"
1759 1759  
1760   -"@vueuse/core@^4.0.0-rc.7":
1761   - version "4.0.0-rc.7"
1762   - resolved "https://registry.npmjs.org/@vueuse/core/-/core-4.0.0-rc.7.tgz#beb2378d97ca03bc65ad05df048df95b1fbf41b0"
1763   - integrity sha512-a45qj5TfihUJ5Q7BGHPjl7J5ugoikEoWCisiHXo2tCiSKoCVIu9GD/p0+ldYeDNyIAQZQuEO2Kn9weP8kw3LiQ==
  1760 +"@vueuse/core@^4.0.0-rc.8":
  1761 + version "4.0.0-rc.8"
  1762 + resolved "https://registry.npmjs.org/@vueuse/core/-/core-4.0.0-rc.8.tgz#d4d1521d8bf1f5a5c45cac4cb81812c9f1d91d1e"
  1763 + integrity sha512-xQGBl9tUMnk0QpqQzdf/awMUW3sQPD9iM2IzmUfcygF43CDDAaoUT8mjH6v8oTm304IJYcjueW2VzqlonxPjwQ==
1764 1764 dependencies:
1765   - "@vueuse/shared" "4.0.0-rc.7"
  1765 + "@vueuse/shared" "4.0.0-rc.8"
1766 1766 vue-demi latest
1767 1767  
1768   -"@vueuse/shared@4.0.0-rc.7":
1769   - version "4.0.0-rc.7"
1770   - resolved "https://registry.npmjs.org/@vueuse/shared/-/shared-4.0.0-rc.7.tgz#3f7095caef42c3d2d7b0ea48bd7652257c95d5c2"
1771   - integrity sha512-KX/JS48jejv6Ezx4TLymjltKlfRFcdw9n9qT89D4J6ygU6cechJEtpD6ACCKGehy8VkW2xKHduvioZtSLr3cNQ==
  1768 +"@vueuse/shared@4.0.0-rc.8":
  1769 + version "4.0.0-rc.8"
  1770 + resolved "https://registry.npmjs.org/@vueuse/shared/-/shared-4.0.0-rc.8.tgz#4f948ad3a5600daaadd3136480ddd26e1cd8f246"
  1771 + integrity sha512-oXPPaKAAdknvXD/unbqsXdZ2E0w1iMYrgAvEqd82ei9STyGBhPL4mQ1aXq4uKwFpVi1Qt6GxXRfAurbvbDox2Q==
1772 1772 dependencies:
1773 1773 vue-demi latest
1774 1774  
... ...