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>
相关推荐
凉辰1 天前
uniapp实现生成海报功能 (开箱即用)
javascript·vue.js·小程序·uni-app
奶糖 肥晨1 天前
微信小程序定位功能开发实战:实现自动定位、城市切换与地图导航
微信小程序·小程序
笨笨狗吞噬者1 天前
【uniapp】小程序支持分包引用分包 node_modules 依赖产物打包到分包中
前端·微信小程序·uni-app
har01d2 天前
uni-app 自动更新检测弹窗,踩坑记录
uni-app
用户69371750013842 天前
微信悄悄搞大事!原生智能助手秘密研发,2026年改变亿人使用习惯
android·后端·微信小程序
CHU7290352 天前
一蔬一饭总关情:生鲜买菜商城APP的生活美学
小程序·生活
CHU7290352 天前
扭蛋机盲盒小程序:趣味交互与惊喜体验的功能设计
前端·小程序
CHU7290352 天前
AI辅助工具小程序:多元功能助力,开启智能便捷新体验
前端·人工智能·小程序
sheji34162 天前
【开题答辩全过程】以 互助式失物招领微信小程序为例,包含答辩的问题和答案
微信小程序·小程序