vue锚点跳转至指定元素位置
注意事项
如果你是页面加载根据传入的数据跳转到指定元素那么一定要写在this.
n
e
x
t
T
i
c
k
中
t
h
i
s
.
nextTick中 this.
nextTick中this.nextTick会在页面数据修改后,重新渲染后的dom中执行
否则有可能dom还没有渲染,就调用获取不到。
this.$nextTick(()=>{
document.querySelector(‘#test’).scrollIntoView({
behavior: "smooth",
block: "start",
inline: "end"
})
// 定义动画过渡效果, "auto"或 "smooth" 之一。默认为 "auto"
// 定义垂直方向的对齐, "start", "center", "end", 或 "nearest"之一。默认为 "start"
// 定义水平方向的对齐, "start", "center", "end", 或 "nearest"之一。默认为 "nearest"
});