Skip to main content
Version: Next

Taro.getWindowInfo()

获取窗口信息

支持情况:

H5: 不支持 statusBarHeight、safeArea

参考文档

类型

() => Result

参数

Result

参数类型必填说明
pixelRationumber设备像素比
screenWidthnumber屏幕宽度,单位px
screenHeightnumber屏幕高度,单位px
windowWidthnumber可使用窗口宽度,单位px
windowHeightnumber可使用窗口高度,单位px
statusBarHeightnumber状态栏的高度,单位px
safeAreaTaroGeneral.SafeAreaResult在竖屏正方向下的安全区域

示例代码

const windowInfo = Taro.getWindowInfo()

console.log(windowInfo.pixelRatio)
console.log(windowInfo.screenWidth)
console.log(windowInfo.screenHeight)
console.log(windowInfo.windowWidth)
console.log(windowInfo.windowHeight)
console.log(windowInfo.statusBarHeight)
console.log(windowInfo.safeArea)
console.log(windowInfo.screenTop)