feat: scroll to top when homepage tab is changed

This commit is contained in:
Hakadao
2023-10-11 01:50:51 +08:00
parent 38a6f20b63
commit 7caa7f3b61
2 changed files with 8 additions and 0 deletions

View File

@@ -19,6 +19,8 @@ import { AppPage, LanguageType } from '~/enums/appEnums'
import { getUserID, hexToRGBA, smoothScrollToTop } from '~/utils/main'
import emitter from '~/utils/mitt'
provide('handleBackToTop', handleBackToTop)
const activatedPage = ref<AppPage>(settings.value.startupPage ?? AppPage.Home)
const { locale } = useI18n()
const [showSettings, toggleSettings] = useToggle(false)

View File

@@ -4,6 +4,8 @@ import Following from './components/Following.vue'
import emitter from '~/utils/mitt'
import { settings } from '~/logic'
const handleBackToTop = inject('handleBackToTop') as () => void
const recommendContentKey = ref<string>(`recommendContent${Number(new Date())}`)
const activatedPage = ref<'RecommendContent' | 'Following'>('RecommendContent')
const pages = { RecommendContent, Following }
@@ -19,6 +21,10 @@ const tabs = reactive<{ label: string; value: 'RecommendContent' | 'Following' }
},
])
watch(() => activatedPage.value, () => {
handleBackToTop()
})
onMounted(() => {
emitter.off('pageRefresh')
emitter.on('pageRefresh', async () => {