這是一個 Vue 指令,它接受一個參數(一個函式),並在使用者捲動包含該 DOM 節點的頁面時觸發。
提示
- 使用此指令的一個替代方案是在您的頁面上放置一個 QScrollObserver 元件。
- 還有另一個與捲動相關的指令可用,稱為 Scroll Fire。
用法
<template>
...
<div v-scroll="onScroll">...</div>
...
</template>
<script>
export default {
setup () {
function onScroll (position) {
// when this method is invoked then it means user
// has scrolled the page to `position`
//
// `position` is an Integer designating the current
// scroll position in pixels.
}
return { onScroll }
}
}
</script>
content_paste
import { debounce } from 'quasar'
export default {
setup () {
function onScroll (position) {
// when this method is invoked then it means user
// has scrolled the page to `position`
//
// `position` is an Integer designating the current
// scroll position in pixels.
}
return {
onScroll: debounce(onScroll, 200) // debounce for 200ms
}
}
}
content_paste
判斷捲動容器
請這裡閱讀關於 Quasar 如何判斷要附加捲動事件的容器。