1,需要通过dom操作获取到对应的h2标签
this.$nextTick(function(){
var h2= document.getElementsByTagName('h2');
this.h2_arr = h2
});
2,文章目录的按钮,添加跳转的点击事件
<div v-for="item in h2_arr" :key="item ">
<el-button @click="gotoEle(item.offsetTop)">{{item.innerHTML}}</el-button>
</div>
3,点击跳转到指定的元素
//点击跳转到指定的元素
gotoEle(offsetTop){
window.scrollTo({'behavior': 'smooth', 'top': offsetTop})
},