1、npm i better-scroll
2、创建一个Scroll的组件,进行封装
<template>
<div class=wrapper ref='myScroll'>
<div class=content>
<slot></slot>
</div>
</div>
</template>
<script>
import BScroll from 'better-scroll'
export default {
name: 'Scroll',
data() {
return {
scroll: null
}
},
mounted() {
this.scroll = new BScroll(this.$refs.myScroll,{
prototype: 3
click:true
pullLoadUp: true:
})
}
this.scroll.on('scroll',(position) => {
console.log(position)
})
this.scroll.refresh()
this.scroll.on('pullingUp',() => {
this.scroll.finishPullUp()
})
this.scroll.scrollTo(x,y,time)
}
</script>