Vue项目 ios 页面留白解决方案(尤其是webView)

问题描述:

进入A页面——>B页面——>ios自带的返回——>白屏出现——>手动点击白屏处——>问题解决

原因分析: 

在ios机器上使用webview开发Vue项目时候,go history(-1), 无法将body的高度拉掉,使得遮住,触发轻点击,方可消除遮罩

解决的理论:

用于最重要的html 容器是container,然而因为设置html、body高度是100%,从而造成了 container 撑开父级,但浏览器默认滚动的scroll 并不是 container(可能我这里认识是错的),而是body,某些因素,造成返回history 后,无法复原(ios 的锅),为此,我们将 container 进行了绝对定位,并让它重新成为 scroll 的对象,从而解决问题

解决方案:

html, body {

    width: 100%;

    height: 100%;

    margin: 0;

    padding: 0;

    position: relative;

}

#app {

    width: 100%;

    height: 100%;

    overflow: scroll;

    -webkit-overflow-scrolling: touch;

    position: absolute;

    left:0;

   top:0;

   padding-bottom: .9rem

}

vue路由跳转处理:

//路由跳转新页面 默认显示在最顶端

router.afterEach((to, from, next) => {

    window.scrollTo(0, 0);

});

文章来源:https://github.com/vuejs/vue/issues/7229

猜你喜欢

转载自blog.csdn.net/baozisss/article/details/81118386
今日推荐