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 }) }
然后就解決了,可以正常滾動。
