vue_zhongyou 1.0.18 → 1.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue_zhongyou",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "keywords": [],
@@ -0,0 +1,14 @@
1
+ // src/main.js
2
+ import { createApp } from 'vue'
3
+ import App from './App.vue'
4
+ import './assets/main.css'
5
+
6
+ // 引入系统缩放感知
7
+ import { initSystemZoom } from './utils/zoom'
8
+
9
+ // 初始化系统缩放
10
+ initSystemZoom()
11
+
12
+ // 创建应用
13
+ const app = createApp(App)
14
+ app.mount('#app')
@@ -0,0 +1,28 @@
1
+ // src/utils/zoom.js
2
+ export function initSystemZoom() {
3
+ // 创建测试元素,测量系统缩放比例
4
+ const testDiv = document.createElement('div')
5
+ testDiv.style.width = '100px'
6
+ testDiv.style.height = '100px'
7
+ testDiv.style.position = 'absolute'
8
+ testDiv.style.top = '-9999px'
9
+ document.body.appendChild(testDiv)
10
+
11
+ // 获取测试元素的实际宽度
12
+ const actualWidth = testDiv.offsetWidth
13
+ document.body.removeChild(testDiv)
14
+
15
+ // 计算系统缩放比例
16
+ const zoomRatio = 100 / actualWidth
17
+
18
+ // 设置rem基准值(16px * 缩放比例)
19
+ const remBase = 16 * zoomRatio
20
+ document.documentElement.style.fontSize = `${remBase}px`
21
+
22
+ console.log(`系统缩放比例: ${zoomRatio.toFixed(2)}, rem基准: ${remBase}px`)
23
+
24
+ // 监听resize事件,处理缩放变化
25
+ window.addEventListener('resize', initSystemZoom)
26
+
27
+ return zoomRatio
28
+ }