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

2021-01-05  本文已影响0人  兜兜里冒糖糖

在普通的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();
    },
上一篇 下一篇

猜你喜欢

热点阅读