需求:有时需要点击页面某个按钮,使页面滑动到某个位置, 解决方法:试一下下面的代码: scrollTo(id,offset) { # id指html中某个元素id,即需要滑动到哪一个id元素 # offset指元素距上顶距离 offset=offset||-10; var el = document.getElementById(id); this.$nextTick(function () { window.scrollTo({ behavior: "smooth", top: el.offsetTop+offset, }); }); },