在 .vuepress/config.js
中加入以下配置:
head: [
[
'script',
{},
`
document.addEventListener("DOMContentLoaded", function(){
console.log("ready");
var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
if (window.location.hash && isChrome) {
setTimeout(function () {
var hash = window.location.hash;
var element_to_scroll_to = document.getElementById(decodeURI(hash.substr(1)));
element_to_scroll_to.scrollIntoView();
}, 300);
}
});
`,
],
],