fixed bug of anchor that will error when add new AnchorLink async
This commit is contained in:
parent
a1fb479092
commit
4556cfa8a5
3 changed files with 24 additions and 6 deletions
|
@ -40,6 +40,11 @@ export default {
|
|||
goAnchor () {
|
||||
this.parentAnchor.turnTo(this.href);
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.$nextTick(() => {
|
||||
this.parentAnchor.init();
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -112,13 +112,16 @@ export default {
|
|||
const links = findComponentsDownward(this, 'AnchorLink').map(link => {
|
||||
return link.href;
|
||||
});
|
||||
const offsetArr = links.map(link => {
|
||||
const id = link.split('#')[1];
|
||||
const idArr = links.map(link => {
|
||||
return link.split('#')[1];
|
||||
});
|
||||
let offsetArr = [];
|
||||
idArr.forEach(id => {
|
||||
const titleEle = document.getElementById(id);
|
||||
return {
|
||||
link: link,
|
||||
if (titleEle) offsetArr.push({
|
||||
link: `#${id}`,
|
||||
offset: titleEle.offsetTop - this.scrollElement.offsetTop
|
||||
};
|
||||
});
|
||||
});
|
||||
this.titlesOffsetArr = offsetArr;
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue