vue使用better-scroll 無法滾動


npm install better-scroll --save-dev  下載了這個插件

在頁面里  import BScroll from 'better-scroll'  引入了這個插件

在template里

<div class="sin">
    <div class="wrapper" ref="singerList">
      <div class="content">
         內容取
       </div>
    </div>
 </div>

css里:

.singer {
  position: absolute;
  width: 100%;
  top: 60px;
  bottom: 0;
}
.wrapper {
  height: 100%;
  overflow: hidden;
}
.content {
  height: auto;
}

在方法里面:

 mounted() {
    this.getSingerData()  //獲取數據的方法

    //實例化
    const wrapper = document.querySelector('.wrapper')
    const scroll = new BScroll('.wrapper', {
      click: true
    })
  },

感覺什么都沒有錯,但是就是不滾動,后來百度發現,說是因為加載這個插件的時候,dom還沒有加載,所以造成了無法滾動;

看不懂別人是怎么寫的,我就想到了vue里面的周期函數:后來改成了

  mounted() {
    this.getSingerData()
  },
  updated() {
    const wrapper = document.querySelector('.wrapper')
    const scroll = new BScroll('.wrapper', {
      click: true
    })
  }

然后就解決了,可以正常滾動。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM