//1在需要监听处放入
@scroll.passive="getScroll($event)"
data(){
return{
scrollbar:'0'
}
},
// methods中监听并赋值
getScroll (e) {
this.scrollbar = e.target.scrollTop
// console.log('1',e.target.scrollHeight)// 总的
// console.log('2',e.target.scrollTop) // 实时
// console.log('3',e.target.clientHeight)
},
//监听上移或下移
watch: {
scrollbar (newVal, oldVal) {
if (newVal> oldVal) {
const below= newVal- oldVal
console.log('向下移动',below)
} else {
const up= oldVal- newVal
console.log('向上移动',up)
}
}
},