Обновить Nuxt Link, как показано ниже
<nuxt-link :to="{path: '/about', hash: '#alex'}">Alex</nuxt-link>
++ Обновлено
Необходимо добавить Режим прокрутки в nuxt.config.js
, как показано ниже
router: {
scrollBehavior: async function(to, from, savedPosition) {
if (savedPosition) {
return savedPosition;
}
const findEl = async (hash, x = 0) => {
return (
document.querySelector(hash) ||
new Promise(resolve => {
if (x > 50) {
return resolve(document.querySelector("#app"));
}
setTimeout(() => {
resolve(findEl(hash, ++x || 1));
}, 100);
})
);
};
if (to.hash) {
let el = await findEl(to.hash);
if ("scrollBehavior" in document.documentElement.style) {
return window.scrollTo({ top: el.offsetTop, behavior: "smooth" });
} else {
return window.scrollTo(0, el.offsetTop);
}
}
return { x: 0, y: 0 };
}
},
Codesandbox Link
Вы также можете использовать пакет vue -scrollto , и если вы используете Vuetify с Nuxt js, тогда доступно $vuetify.goTo
.