vue 列表滚动条和safari自带滚动条冲突问题

在普通的html页面中消除safari 自带的滚动条 只需要给body加一个overflow: hidden;就行了,
在vue 页面中 也是如此,只是在单独页面中加稍微麻烦一点,
如果页面没有使用keep-alive 缓存的话

 //创建前设置
    beforeCreate () {
      document.querySelector('body').setAttribute('style', 'overflow:hidden;')
    },
 //销毁前清除
    beforeDestroy () {
      document.querySelector('body').removeAttribute('style')
    },      

如果使用了缓存 beforeDestroy 会不执行, 可以换成

    //路由进入之前
    beforeRouteEnter (to, from, next) {
      document.querySelector('body').setAttribute('style', 'overflow:hidden;')
      next();
    },
    //路由离开之前
    beforeRouteLeave (to, from, next) {
      document.querySelector('body').removeAttribute('style')
        next();
    },
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容