fix: 'textContent' of undefined and text wrapping (#1973)

This commit is contained in:
啝裳 2021-05-21 15:34:14 +08:00 committed by GitHub
parent 79876b9733
commit aca8a21f79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -48,7 +48,7 @@ export default defineComponent({
if (!content) return
const h3 = content.querySelectorAll('h3')
anchors.value = Array.from(h3).map(item => {
const text = item.childNodes[1].textContent.trim()
const text = item.childNodes[1] && item.childNodes[1].textContent.trim()
map.set(text, item.offsetTop)
return text
})
@ -57,7 +57,7 @@ export default defineComponent({
let mapKeys = Array.from(map.keys()).reverse()
resizeObserver = new ResizeObserver(() => {
Array.from(h3).forEach(item => {
const text = item.childNodes[1].textContent.trim()
const text = item.childNodes[1] && item.childNodes[1].textContent.trim()
map.set(text, item.offsetTop)
})
mapValues = Array.from(map.values()).reverse()

View File

@ -214,6 +214,10 @@ export default {
position: relative;
transition: .15s ease-out;
font-weight: bold;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-weight: normal;
&.active {
color: #409EFF;