diff --git a/example/app.js b/example/app.js index 392992f..274150d 100644 --- a/example/app.js +++ b/example/app.js @@ -113,8 +113,24 @@ const titleAndDescMap = transformMd(en); const App = { name: 'App', + data() { + return { + currentId: this.getCurrentId(), + }; + }, mounted() { hljs.initHighlighting(); + window.onhashchange = () => { + this.currentId = this.getCurrentId(); + }; + if (this.currentId) { + document.getElementById(this.currentId).scrollIntoView(); + } + }, + methods: { + getCurrentId() { + return location.hash.slice(1); + }, }, render(h) { const menus = components.map(item => { @@ -130,6 +146,7 @@ const App = { const props = { id, code, + active: id === this.currentId, ...titleAndDescMap[id], }; return {h(component)}; diff --git a/example/helper/card.vue b/example/helper/card.vue index 6cdeef1..ee5c013 100644 --- a/example/helper/card.vue +++ b/example/helper/card.vue @@ -1,5 +1,5 @@