2024-10-28 13:25:45 +08:00
|
|
|
|
import { ref } from 'vue'
|
|
|
|
|
|
|
|
|
|
|
|
export const useViewSize = () => {
|
|
|
|
|
|
|
|
|
|
|
|
const popupBaseView = ref(null)
|
2024-11-01 13:29:00 +08:00
|
|
|
|
const viewWidth = ref(0)
|
|
|
|
|
|
const viewHeight = ref(0)
|
2024-10-28 13:25:45 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 更新宽和高的数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
const updateDimensions = () => {
|
|
|
|
|
|
if (popupBaseView.value) {
|
2024-11-01 13:29:00 +08:00
|
|
|
|
viewWidth.value = popupBaseView.value.offsetWidth
|
|
|
|
|
|
viewHeight.value = popupBaseView.value.offsetHeight
|
2024-10-28 13:25:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 组件挂载完毕,计算宽高,并且给浏览器添加监听器,监听窗口大小改变
|
|
|
|
|
|
*/
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
updateDimensions()
|
|
|
|
|
|
window.addEventListener('resize', updateDimensions)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 组件视图更新完毕,计算宽高
|
|
|
|
|
|
*/
|
|
|
|
|
|
onUpdated(() => {
|
|
|
|
|
|
updateDimensions()
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return { popupBaseView, viewWidth, viewHeight }
|
|
|
|
|
|
|
|
|
|
|
|
}
|