From 9ea53a592310141c34eea07609919876df50296e Mon Sep 17 00:00:00 2001 From: mengxiong10 <15623530290@163.com> Date: Tue, 12 Nov 2019 12:14:25 +0800 Subject: [PATCH] docs(example): optimized selected el --- example/app.js | 17 ++++++++++++++ example/helper/card.vue | 12 +++++++--- example/helper/container.vue | 43 +++++++++++++++++++++++------------- 3 files changed, 54 insertions(+), 18 deletions(-) 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 @@