mixin.js
1.03 KB
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
/*
* @Date: 2022-07-26 09:49:54
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-10-10 13:53:54
* @FilePath: /hager/src/common/mixin.js
* @Description: 文件描述
*/
import $ from 'jquery';
export default {
// 初始化设置
init: {
mounted () {
document.title = this.$route.meta.title;
// 页面进入时获取当前屏幕宽度
this.handleResize();
// 监听窗口的 resize 事件
window.addEventListener('resize', this.handleResize);
},
beforeDestroy() {
// 在组件销毁前移除监听器,防止内存泄漏
window.removeEventListener('resize', this.handleResize);
},
data () {
return {
top_img_height: '35rem',
screenWidth: $('.hagerBox').width(), // 初始化屏幕宽度, xs <768px
};
},
computed: {
is_xs () {
return this.screenWidth < 768;
}
},
methods: {
handleResize() {
this.screenWidth = $('.hagerBox').width(); // 更新屏幕宽度
},
},
},
};