Skip to content

Commit

Permalink
add remeber markmap state
Browse files Browse the repository at this point in the history
  • Loading branch information
Xicheng Guo committed May 30, 2024
1 parent 0f35715 commit da3bfcc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/MarkMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}
});
}
};
Expand Down
8 changes: 6 additions & 2 deletions src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import MarkMap from './MarkMap.vue';
</script>

<MarkMap markdown="
- JS全栈
- JS全栈知识体系
- JavaScript
- JavaScript 介绍
- [JavaScript 发展历程](javascript/introduction/history-of-javascript)
Expand All @@ -17,7 +17,11 @@ import MarkMap from './MarkMap.vue';
- [ES 的版本](javascript/ecma-script/es-version)
- JavaScript 引擎
- [调用栈](javascript/ecma-script/javascript-engine/call-stack)
- [作用域](javascript/ecma-script/javascript-engine/scope)
- 作用域
- [什么是作用域](javascript/ecma-script/javascript-engine/scope#什么是作用域)
- [全局作用域](javascript/ecma-script/javascript-engine/scope#全局作用域)
- [函数作用域](javascript/ecma-script/javascript-engine/scope#函数作用域)
- [块级作用域](javascript/ecma-script/javascript-engine/scope#块级作用域)
- [作用域链](javascript/ecma-script/javascript-engine/scope-chain)
- [this 关键字](javascript/ecma-script/javascript-engine/this-keyword)
- [变量声明](javascript/ecma-script/variable-declaration)
Expand Down
6 changes: 3 additions & 3 deletions src/javascript/ecma-script/javascript-engine/scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ JavaScript 遵循词法作用域。

:::

### 全局作用域
## 全局作用域

全局作用域是指在代码中任何地方都能访问的变量和函数。

Expand All @@ -26,7 +26,7 @@ function foo() {
foo(); // 1
```

### 函数作用域
## 函数作用域

函数作用域是指在函数内部定义的变量和函数只能在函数内部访问。

Expand All @@ -39,7 +39,7 @@ foo(); // 1
console.log(a); // ReferenceError: a is not defined
```

### 块级作用域
## 块级作用域

块级作用域是指在代码块内部定义的变量和函数只能在代码块内部访问。

Expand Down

0 comments on commit da3bfcc

Please sign in to comment.