-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
43 lines (41 loc) · 910 Bytes
/
App.vue
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
<template>
<div id="app">
<router-view />
</div>
</template>
<script>
import { mapMutations } from 'vuex';
export default {
data() {
return {
timer: null
};
},
created() {
this.resize();
window.addEventListener('resize', () => {
// 防抖处理
if (this.timer) {
clearTimeout(this.timer);
}
this.timer = setTimeout(() => {
this.resize();
}, 200);
});
},
methods: {
...mapMutations(['SET_MOBILE']),
// 动态font-size
resize: function() {
let screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
if (screenWidth < 769) {
document.getElementsByTagName('html')[0].style.fontSize = 20 * (screenWidth / 375) + 'px';
this.SET_MOBILE(true);
} else {
document.getElementsByTagName('html')[0].style.fontSize = 20 * (screenWidth / 960) + 'px';
this.SET_MOBILE(false);
}
}
}
};
</script>