uniapp页面横屏设置

427 阅读1分钟

vue2

	onLoad() {
			setTimeout(() => {
				plus.screen.unlockOrientation();
				plus.screen.lockOrientation('landscape-primary');
 
			}, 500)
		},
		onUnload() {
			plus.screen.lockOrientation('portrait-primary');
		},

vue3

<script setup>
	import {
		onMounted
	} from 'vue';

	onMounted(() => {
		setTimeout(() => {
			plus.screen.unlockOrientation();
			plus.screen.lockOrientation('landscape-primary');

		}, 600)
	});
</script>

如果想整个应用横屏的话在`App.vue设置

监听横竖屏切换

<script setup>
	import {onResize} from '@dcloudio/uni-app'
	onResize(()=>{
		console.log('横竖屏切换')
	})
</script>