From 8382fd15ad7bd612a1969a34ca5e37bcbf4521cf Mon Sep 17 00:00:00 2001 From: neverland <chenjiahan@youzan.com> Date: Fri, 10 Sep 2021 11:07:28 +0800 Subject: [PATCH] fix(@vant/cli): should allow to click anchor (#9434) * fix(@vant/cli): should allow to click anchor * chore: add --- packages/vant/.stylelintrc => .stylelintrc | 0 .../site/desktop/components/Content.vue | 18 ++++++++++++++++++ packages/vant-cli/site/tsconfig.json | 6 ++++++ packages/vant-cli/tsconfig.json | 2 +- 4 files changed, 25 insertions(+), 1 deletion(-) rename packages/vant/.stylelintrc => .stylelintrc (100%) create mode 100644 packages/vant-cli/site/tsconfig.json diff --git a/packages/vant/.stylelintrc b/.stylelintrc similarity index 100% rename from packages/vant/.stylelintrc rename to .stylelintrc diff --git a/packages/vant-cli/site/desktop/components/Content.vue b/packages/vant-cli/site/desktop/components/Content.vue index f18d77ad7..26236165b 100644 --- a/packages/vant-cli/site/desktop/components/Content.vue +++ b/packages/vant-cli/site/desktop/components/Content.vue @@ -17,6 +17,24 @@ export default { return this.$route.name; }, }, + + 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) { + this.$router.push({ + name: this.$route.name, + hash: '#' + event.target.id, + }); + } + }, + }, }; </script> diff --git a/packages/vant-cli/site/tsconfig.json b/packages/vant-cli/site/tsconfig.json new file mode 100644 index 000000000..2f10c52d6 --- /dev/null +++ b/packages/vant-cli/site/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "allowJs": true + } +} diff --git a/packages/vant-cli/tsconfig.json b/packages/vant-cli/tsconfig.json index 8921c1271..84c0d6e5a 100644 --- a/packages/vant-cli/tsconfig.json +++ b/packages/vant-cli/tsconfig.json @@ -9,5 +9,5 @@ "esModuleInterop": true, "lib": ["esnext", "dom"] }, - "include": ["src/**/*", "site"] + "include": ["src/**/*"] }