From da3bfcc27d8c738413d5483274cc9091ce4bb9aa Mon Sep 17 00:00:00 2001 From: Xicheng Guo Date: Thu, 30 May 2024 11:10:40 +0800 Subject: [PATCH] add remeber markmap state --- src/MarkMap.vue | 11 ++++++++++- src/index.md | 8 ++++++-- src/javascript/ecma-script/javascript-engine/scope.md | 6 +++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/MarkMap.vue b/src/MarkMap.vue index 0ad1043..33cce04 100644 --- a/src/MarkMap.vue +++ b/src/MarkMap.vue @@ -26,7 +26,16 @@ export default { if (assets.styles) loadCSS(assets.styles); if (assets.scripts) loadJS(assets.scripts, { getMarkmap: () => window.markmap }); - Markmap.create('#markmap', null, root); + const savedState = JSON.parse(localStorage.getItem('markmap-state')); + const markmapState = savedState ? savedState : root; + + const markmap = Markmap.create('#markmap', null, markmapState); + + for (const item of document.getElementsByTagName('circle')) { + item.addEventListener('click', () => { + localStorage.setItem('markmap-state', JSON.stringify(markmap.state.data)); + }); + } }); } }; diff --git a/src/index.md b/src/index.md index 1f87ad5..dd52ad6 100644 --- a/src/index.md +++ b/src/index.md @@ -8,7 +8,7 @@ import MarkMap from './MarkMap.vue';