我是靠谱客的博主 奋斗香氛,这篇文章主要介绍vue3里监听window事件(放大缩小devicePixelRatio)或者document事件(窗口宽高变化documentElement.clientWidth),现在分享给大家,希望可以做个参考。
监听放大缩小事件 window.devicePixelRatio
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25let backup onMounted(() => { window.onresize = async () => { const devicePixelRatio = window.devicePixelRatio /** * 若工程是最后一页或是只有第一页就不进行加载 * 且 第一次加载缩小备份devicePixelRatio是未定义 或者 备份devicePixelRatio大于当前devicePixelRatio值 则刷新 **/ if ((ifLast.value === 0) && devicePixelRatio < 1 && ((backup === undefined) || (backup !== undefined && backup > devicePixelRatio))) { backup = window.devicePixelRatio if (selectedGroupKeys.value[0] === 0) { await requestProjectList() } else { await requestProjectListById() } } } }) onUnmounted(() => { // 组件销毁后解绑事件 window.onresize = null })
监听窗口高度是否改变事件
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23const changeJustifyContent = () => { const browseContentWidth = parseInt(currentSlide.value.width) * scale.value const documentWidth = document.documentElement.clientWidth if (browseContentWidth >= documentWidth) { justifyContent.value = 'flex-start' } else { justifyContent.value = 'center' } } onMounted(() => { window.onresize = () => { console.log('change') changeJustifyContent() } }) onUnmounted(() => { // 组件销毁后解绑事件 window.onresize = null })
最后
以上就是奋斗香氛最近收集整理的关于vue3里监听window事件(放大缩小devicePixelRatio)或者document事件(窗口宽高变化documentElement.clientWidth)的全部内容,更多相关vue3里监听window事件(放大缩小devicePixelRatio)或者document事件(窗口宽高变化documentElement内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复