我可以实现smooth-scroll
router-links
:
<router-link :to="{ hash: 'home' }">Home</router-link>
<router-link :to="{ hash: 'about' }">About</router-link>
和router.js
:
import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../vue/home";
import About from "../vue/about";
Vue.use(VueRouter);
export default new VueRouter ({
mode: "history",
routes: [
{path: "/", name: "home", component: Home},
{path: "/about", name: "about", component: About},
],
scrollBehavior(to, from, savedPosition) {
return {
selector: to.hash,
behavior: 'smooth'
}
}
});
与vue's
v-smooth-scroll
类相比,smooth-scroll
类的效果稍慢。有没有办法控制VueRouter
的smooth-scroll
速度?
No.
Vue路由器的平滑滚动在实现本地浏览器APIScrollToOptions.behavior
。这是由客户端的浏览器控制的。这可能因系统而异。