uniapp中使用mixins控制横屏竖屏

概念

mixins概念和用法同vue在此不在赘述。

在根目录下创建mixins目录,在mixins目录下创建lockScreen.js

export default {
	data() {
		return {};
	},
	onLoad() {
		// #ifndef H5
		plus.screen.lockOrientation('portrait-primary');
		// #endif
	},
	onShow: function() {},
	onUnload() {},
	methods: {
		// 设置屏幕方向为横屏
		setScreenAuto() {
			// #ifndef H5
			plus.screen.lockOrientation('auto');
			// #endif
		},
		// 设置屏幕方向为横屏
		setScreenLandscape() {
			// #ifndef H5
			plus.screen.lockOrientation('landscape-primary');
			// #endif
		},
		// 设置屏幕方向为竖屏
		setScreenPortrait() {
			// #ifndef H5
			plus.screen.lockOrientation('portrait-primary');
			// #endif
		},
		kaifazhong() {
			uni.showToast({
				title: "公测暂未开放",
				icon: "none"
			})
		}
	}
};

然后在main.js中引入mixins

import lockScreen from '@/mixins/lockScreen.js'

// 注册全局混入
Vue.mixin(lockScreen)

在页面中使用

// /pages/webview/webview
<template>
	<view>
		<web-view :src="webUrl" frameborder="0"
			style="position: absolute; left: 0px; top: 0; height: 100%;"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				webUrl: ''
			}
		},
		onLoad(params) {
			this.setScreenAuto();
			this.webUrl = params.url
		},
		onUnload() {
			this.setScreenPortrait()
		},
		methods: {
			
		}
	}
</script>

<style lang="scss" scoped>
::-webkit-scrollbar {
  width: 0;
  height: 0;
}
</style>

相关推荐

  1. uniapp使用mixins控制

    2024-03-22 05:02:02       40 阅读
  2. APP开发_ js 控制手机

    2024-03-22 05:02:02       35 阅读
  3. uniapp 设置某个页面显示

    2024-03-22 05:02:02       55 阅读
  4. uniapp实现手机(方法二)

    2024-03-22 05:02:02       50 阅读
  5. uniapp页面进来直接

    2024-03-22 05:02:02       27 阅读
  6. Android 13.0 recovery界面旋转为

    2024-03-22 05:02:02       56 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-22 05:02:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-22 05:02:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-03-22 05:02:02       82 阅读
  4. Python语言-面向对象

    2024-03-22 05:02:02       91 阅读

热门阅读

  1. 微信授权登录获取用户openid

    2024-03-22 05:02:02       40 阅读
  2. 相向双指针

    2024-03-22 05:02:02       33 阅读
  3. RabbitMQ docker 单机部署

    2024-03-22 05:02:02       44 阅读
  4. vue绑定key

    2024-03-22 05:02:02       39 阅读
  5. AGI的数据驱动:挖掘海量信息的价值与智慧

    2024-03-22 05:02:02       45 阅读
  6. Mysql批量更新: on duplicate key update

    2024-03-22 05:02:02       45 阅读