获取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)
					}
				})
			},

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐