uniapp APP和微信小程序横屏模式

首先在pages.json下新增代码:

复制代码
"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8",
		"pageOrientation": "auto" //横屏配置 auto自动 | portrait竖屏 | landscape横屏
	},

微信小程序横屏:

pages.json下添加代码(进入页面自动横横屏):

复制代码
{
			"path": "pages/native/demo",
			"style": {
				"navigationBarTitleText": "横屏模式",
				"enablePullDownRefresh": false,
				"backgroundTextStyle": "dark",
				"mp-weixin": {
					"pageOrientation": "landscape" //auto:自动,landscape:横屏,portrait :竖屏
				}
			}
		}

页面代码实现:

复制代码
<template>
	<view class="">
		<button type="default" @click="onCrosswise('default')">默认横竖屏切换</button>
		<button type="default" @click="onCrosswise('portrait')">竖屏</button>
		<button type="default" @click="onCrosswise('landscape')">横屏</button>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		watch,
		onMounted,
	} from "vue"
	import {
		onLoad,
		onReady,
		onUnload
	} from '@dcloudio/uni-app'

// 切换模式
	const onCrosswise = (mode) => {
		if (mode == 'default') {
			// #ifdef APP-PLUS
			plus.screen.lockOrientation('default'); // 默认横竖屏切换
			// #endif
		} else if (mode == 'portrait') {
			// #ifdef APP-PLUS
			plus.screen.lockOrientation('portrait-primary'); // 竖屏展示
			// #endif
		} else {
			uni.navigateTo({
				url: "/pages/native/demo",
				success: function(res) {
					// #ifdef APP-PLUS
					plus.screen.lockOrientation('landscape-primary'); // 强制横屏
					// #endif
				}
			})
		}
	}
</script>

/pages/native/demo页面:

复制代码
<template>
	<view class="">
		跳转成功
	</view>
</template>

<script setup>
	import {
		onLoad,
		onReady,
		onUnload
	} from '@dcloudio/uni-app'
	//页面卸载时切换为默认或者其他属性
	onUnload(() => {
		{
			// #ifdef APP-PLUS
			plus.screen.lockOrientation('default');
			// #endif
		}
	})
</script>

<style>
</style>
相关推荐
CHU72903521 小时前
便捷约玩,沉浸推理:线上剧本杀APP功能版块设计详解
前端·小程序
px不是xp1 天前
微信小程序组件化开发最佳实践
微信小程序·小程序·notepad++
曲江涛1 天前
微信小程序 摄像头 授权同页面丝滑调用
微信小程序
code_Bo1 天前
kiro生成小程序商业案例
前端·微信小程序·小程序·云开发
软希网分享源码1 天前
中英双语言量化交易投资源码/跟单搬砖区块链交易所源码/前端uniapp纯源码+后端
前端·uni-app·区块链·中英双语言量化交易投资源码
小成Coder1 天前
UniApp 如何调用鸿蒙预加载
uni-app·harmonyos·鸿蒙
编程迪1 天前
基于SpringBoot开发的预约停车系统共享停车位小程序app
小程序·停车场小程序·预约停车·错峰出行·共享车位app
云起SAAS1 天前
早晚安打卡签到小程序完整源码 | 三级分销+红包广告+PC后台 | 商业级系统
小程序
职豚求职小程序1 天前
浙商银行笔试题库小程序练习2026新版题库
小程序
Kingexpand_com1 天前
旅游小程序选型指南:模板与定制开发全解析
小程序·旅游·软件开发·小程序开发·旅游小程序·旅行·定制开发