fix: avoid using async in onMounted

This commit is contained in:
Hakadao
2024-12-15 22:51:12 +08:00
parent 47644b530e
commit fc902f7e74
10 changed files with 55 additions and 46 deletions

View File

@@ -28,12 +28,13 @@ nextTick(() => {
useEventListener(iframeRef.value?.contentWindow, 'popstate', updateCurrentUrl)
})
onMounted(async () => {
onMounted(() => {
history.pushState(null, '', props.url)
show.value = true
headerShow.value = true
await nextTick()
iframeRef.value?.focus()
nextTick(() => {
iframeRef.value?.focus()
})
})
onBeforeUnmount(() => {

View File

@@ -285,20 +285,21 @@ watch(activatedPage, () => {
toggleTopBarVisible(true)
})
onMounted(async () => {
onMounted(() => {
initData()
await nextTick()
toggleTopBarVisible(true)
nextTick(() => {
toggleTopBarVisible(true)
emitter.off(OVERLAY_SCROLL_BAR_SCROLL)
if (isHomePage() && !settings.value.useOriginalBilibiliHomepage) {
emitter.on(OVERLAY_SCROLL_BAR_SCROLL, () => {
handleScroll()
})
}
else {
window.addEventListener('scroll', handleScroll)
}
emitter.off(OVERLAY_SCROLL_BAR_SCROLL)
if (isHomePage() && !settings.value.useOriginalBilibiliHomepage) {
emitter.on(OVERLAY_SCROLL_BAR_SCROLL, () => {
handleScroll()
})
}
else {
window.addEventListener('scroll', handleScroll)
}
})
})
onUnmounted(() => {
@@ -519,9 +520,9 @@ defineExpose({
<SearchBar
v-if="showSearchBar"
style="
--b-search-bar-normal-color: var(--bew-elevated);
--b-search-bar-hover-color: var(--bew-elevated-hover);
"
--b-search-bar-normal-color: var(--bew-elevated);
--b-search-bar-hover-color: var(--bew-elevated-hover);
"
/>
</Transition>
</div>

View File

@@ -277,20 +277,20 @@ watch(activatedPage, () => {
toggleTopBarVisible(true)
})
onMounted(async () => {
onMounted(() => {
initData()
await nextTick()
toggleTopBarVisible(true)
emitter.off(OVERLAY_SCROLL_BAR_SCROLL)
if (isHomePage() && !settings.value.useOriginalBilibiliHomepage) {
emitter.on(OVERLAY_SCROLL_BAR_SCROLL, () => {
handleScroll()
})
}
else {
window.addEventListener('scroll', handleScroll)
}
nextTick(() => {
toggleTopBarVisible(true)
emitter.off(OVERLAY_SCROLL_BAR_SCROLL)
if (isHomePage() && !settings.value.useOriginalBilibiliHomepage) {
emitter.on(OVERLAY_SCROLL_BAR_SCROLL, () => {
handleScroll()
})
}
else {
window.addEventListener('scroll', handleScroll)
}
})
})
onUnmounted(() => {

View File

@@ -44,7 +44,11 @@ watch(activatedMediaId, (newVal: number, oldVal: number) => {
getFavoriteResources()
})
onMounted(async () => {
onMounted(() => {
initData()
})
async function initData() {
await getFavoriteCategories()
activatedMediaId.value = favoriteCategories[0].id
activatedFavoriteTitle.value = favoriteCategories[0].title
@@ -67,7 +71,7 @@ onMounted(async () => {
}
})
}
})
}
async function getFavoriteCategories() {
await api.favorite.getFavoriteCategories({