uniapp 获取app横竖屏方向
·
获取app横竖屏方向:
orientation: 'landscape' // portrait:竖屏, landscape:横屏
mounted() {
this.getInitialOrientation()
// 监听屏幕旋转
uni.onWindowResize((res) => {
const width = res.size.windowWidth
const height = res.size.windowHeight
this.orientation = width > height ? 'landscape' : 'portrait'
console.log('当前方向:', this.orientation)
})
},
// 主动获取初始屏幕方向
getInitialOrientation() {
uni.getSystemInfo({
success: (res) => {
const width = res.windowWidth
const height = res.windowHeight
this.orientation = width > height ? 'landscape' : 'portrait'
console.log('初始方向:', this.orientation)
}
})
},
更多推荐


所有评论(0)