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>
相关推荐
小羊Yveesss19 小时前
模板建站哪个平台好?模板数量之外还要比较编辑与SEO能力
大数据·人工智能·小程序
2501_9160074720 小时前
深入理解HTTPS对称与非对称加密机制及Charles抓包实践
网络协议·http·ios·小程序·https·uni-app·iphone
郑州光合科技余经理20 小时前
家政O2O平台解析:从0搭建上门预约小程序解决方案
android·java·开发语言·前端·小程序·架构·php
小徐_233321 小时前
AI 写 wot-ui 总在猜 API?我们把 Skills、MCP 和 CLI 都配好了
前端·uni-app·ai编程
维双云21 小时前
小程序商城制作一个需要多少钱?2026报价明细与成本拆解
小程序
Liu.77421 小时前
uni-app 组件 uni-easyinput 常见 Bug 及解决方案
uni-app·bug
郑州光合科技余经理1 天前
家政预约小程序后端源码深度剖析:支付回调实战
java·开发语言·前端·git·小程序·架构·php
电商API_180079052471 天前
导购比价小程序场景|京东联盟商品详情对接方案|多规格图文拉取技术实操
网络·小程序·网络爬虫
北极糊的狐1 天前
钉钉小程序 Git 版本管理完整流程
git·小程序·钉钉
码农学院1 天前
微信小程序云开发实战:扫码点餐系统的高并发订单处理与外卖接单架构
微信小程序·架构·notepad++