(跳转此页面时,在路由后面跟上?#tab1)
TAB1
<div id='tab1' name='tab1' ref="tab1">
第一部分内容区域
</div >
TAB2
<div id='tab1' name='tab1' ref="tab1">
第二部分内容区域
</div >
在mounted里
// 锚点跳转
mounted: function () {
var hash = window.location.hash;
var index = hash.lastIndexOf("#");
if (index != -1) {
var id = hash.substring(index + 1, hash.length + 1);
var div = document.getElementById(id);
if (div) {
setTimeout(function () {
console.log($(div).offset().top);
//$('html,body').scrollTop($(div).offset().top - 43);
$('html, body').animate({scrollTop: $(div).offset().top - 43}, 500)
}, 500);
}
}
},