From 8dcda1bd10651a1401899207ddcf747ef98c592d Mon Sep 17 00:00:00 2001 From: zyronon Date: Thu, 30 May 2024 10:46:41 +0800 Subject: [PATCH] fix: root font-size automatic adaptation --- src/App.vue | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/App.vue b/src/App.vue index bed79da..6e01317 100644 --- a/src/App.vue +++ b/src/App.vue @@ -53,18 +53,19 @@ watch( } ) -function setVh() { +function resetVhAndPx() { let vh = window.innerHeight * 0.01 document.documentElement.style.setProperty('--vh', `${vh}px`) + document.documentElement.style.fontSize = document.documentElement.clientWidth / 375 + 'px' } onMounted(() => { store.init() - setVh() + resetVhAndPx() // 监听resize事件 视图大小发生变化就重新计算1vh的值 window.addEventListener('resize', () => { location.href = BASE_URL + '/' - setVh() + resetVhAndPx() }) })