fix(@vant/cli): added markdown link open plugin (#9597)

This commit is contained in:
neverland
2021-09-30 10:45:55 +08:00
committed by GitHub
parent 6a054ca0e3
commit 1457a27fb4
4 changed files with 61 additions and 12 deletions

View File

@@ -1,5 +1,8 @@
<template>
<div :class="['van-doc-content', `van-doc-content--${currentPage}`]">
<div
:class="['van-doc-content', `van-doc-content--${currentPage}`]"
@click="onClick"
>
<slot />
</div>
</template>
@@ -18,19 +21,18 @@ export default {
},
},
mounted() {
const anchors = [].slice.call(this.$el.querySelectorAll('h2, h3, h4, h5'));
anchors.forEach((anchor) => {
anchor.addEventListener('click', this.scrollToAnchor);
});
},
methods: {
scrollToAnchor(event) {
if (event.target.id) {
onClick({ target }) {
if (['H2', 'H3', 'H4', 'H5'].includes(target.tagName)) {
this.scrollToAnchor(target);
}
},
scrollToAnchor(target) {
if (target.id) {
this.$router.push({
name: this.$route.name,
hash: '#' + event.target.id,
hash: '#' + target.id,
});
}
},