项目应用场景:在用cordova做webapp时,项目需要默认为横屏,我在config.xml里设置了<preference name="Orientation" value="landscape" />达到了想要的效果,现在做二开的时候,新的几个界面需要强制竖屏
要实现以上方法需要我们采用cordova的插件
cordova-plugin-screen-orientation
不清楚地小伙伴可以点击这查看下
在需要横屏的组件的 created
函数中写入
screen.orientation.lock('landscape');
在 beforeDestroy
中写入:
screen.orientation.unlock();
如果很多页面都需要横竖屏切换的话可以采用以下方案:
在vue-router路由里自定义一个meta变量来管理是否需要横竖屏 如下screen
然后在beforeEach里做出对应的处理
这样就能达到部分页面切换为横屏的效果啦