const headingGroup = this.$refs.preview.$el.querySelectorAll('h1,h2,h3,h4,h5,h6')
for (let i = 0; i < headingGroup.length; ++i) {
if (headingGroup[i].innerText === (anchor.title)) {
headingGroup[i].scrollIntoView({
behavior: 'smooth',
block: 'start'
})
}
对于在vue里实现鼠标点击锚点功能 可以使用枚举
当点击某段标题时 可以直接调用上段代码 把浏览器焦点移到目标区域
对于访问NodeList方式:直接数组下标索引即可。