1.创建usePageOrientation.ts文件
export function usePageOrientation() {
const lockLandscape = () => {
// #ifdef APP-PLUS
plus.screen.lockOrientation('landscape-primary')
// #endif
}
const restorePortrait = () => {
// #ifdef APP-PLUS
plus.screen.lockOrientation('portrait-primary')
// #endif
}
return {
lockLandscape,
restorePortrait,
}
}
2.在a页面引入onShow中执行restorePortrait
import { usePageOrientation } from '@/hooks/usePageOrientation'
const { lockLandscape, restorePortrait } = usePageOrientation()
onShow(() => {
restorePortrait()
})
3.从a页面跳转到b页面,页面设置为横屏
import { usePageOrientation } from '@/hooks/usePageOrientation'
const { lockLandscape, restorePortrait } = usePageOrientation()
onLoad((options: any) => {
lockLandscape()
})
4.从b页面返回a页面,然后快速点击返回按钮,应用偶尔会闪退