老师,我这边的问题是probeType配置了值为3,但是好像并没有触发那种滚动动画(此时鼠标不在滚动区域)时的scroll事件, 只有鼠标拖动才会连续触发scroll事件。
index-list.vue
<scroll
class="index-list"
ref="scrollRef"
probe-type="3"
@scroll="onScroll"
>
scroll.vue
<template>
<div ref="rootRef">
<slot></slot>
</div>
</template>
<script>
import { ref } from 'vue'
import useScroll from './use-scroll'
export default {
name: 'scroll',
props: {
click: {
type: Boolean,
default: true
},
probeType: {
type: Number,
default: 0
}
},
emits: ['scroll'],
setup(props, { emit }) {
const rootRef = ref(null)
const { scroll } = useScroll(rootRef, props, emit)
return {
rootRef,
scroll
}
}
}
</script>
use-scroll.js
onMounted(() => {
const scrollVal = scroll.value = new BScroll(wrapperRef.value, {
observeDOM: true,
...options
})
if (options.probeType > 0) {
scrollVal.on('scroll', (pos) => {
emit('scroll', pos)
})
}
})
慕课网明星讲师黄轶深度讲解 Vue3.0 ,提升的不止是Vue代码能力
了解课程