Administrator
2022-04-11 79d9fc857559982b00b68b2d709807bdc4cd286f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import _this from "../main";
 
// 设置 init 函数
function init() {
  if (_this) {
    let innerWH = {
      innerWidth: window.innerWidth,
      innerHeight: window.innerHeight
      // innerWidth: document.documentElement.clientWidth,
      // innerHeight: document.documentElement.clientHeight,
    };
    _this.$store.commit("setWindowSize", innerWH);
    _this.$store.commit("setWindowSizeHeight", innerWH.innerHeight);
    _this.$store.commit("setScreenSize", {
      w: window.screen.width,
      h: window.screen.height
    });
 
    // console.log("第下次判断屏幕分辨率");
    // console.log(' window.innerWidth', window.innerWidth);
    // console.log(' window.innerHeight', window.innerHeight);
    _this.$store.dispatch("changeZoom");
  }
}
 
// 节流 ms 触发间隔毫秒
var ms = 300;
var lastClick = Date.now() - ms;
// 初始化
setTimeout(() => {
  init();
}, 500);
// 改变窗口大小时重新设置 rem
// window.onresize = function () {
//     // 节流
//     if (Date.now() - lastClick >= ms) {
//         init();
//         lastClick = Date.now();
//     }
// }
window.addEventListener(
  "resize",
  () => {
    // 节流
    if (Date.now() - lastClick >= ms) {
      init();
      lastClick = Date.now();
    }
  },
  false
);