⬅️ Back to Table of Contents
📄 directive.ts
📊 Analysis Summary
Metric |
Count |
🔧 Functions |
1 |
📦 Imports |
4 |
📊 Variables & Constants |
2 |
📑 Type Aliases |
2 |
📚 Table of Contents
🛠️ File Location:
📂 packages/core/useScroll/directive.ts
📦 Imports
Name |
Source |
ObjectDirective |
vue |
UseScrollOptions |
./index |
UseScrollReturn |
./index |
useScroll |
./index |
Variables & Constants
Name |
Type |
Kind |
Value |
Exported |
handler |
any |
const |
binding.value |
✗ |
vScroll |
`ObjectDirective< |
|
|
|
HTMLElement, |
|
|
|
|
BindingValueFunction |
BindingValueArray |
|
|
|
>| const | { |
|
|
|
|
mounted(el, binding) { |
|
|
|
|
if (typeof binding.value === 'function') { |
|
|
|
|
const handler = binding.value |
|
|
|
|
const state = useScroll(el, { |
|
|
|
|
onScroll() { |
|
|
|
|
handler(state) |
|
|
|
|
}, |
|
|
|
|
onStop() { |
|
|
|
|
handler(state) |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
const [handler, options] = binding.value |
|
|
|
|
const state = useScroll(el, { |
|
|
|
|
...options, |
|
|
|
|
onScroll(e) { |
|
|
|
|
options.onScroll?.(e) |
|
|
|
|
handler(state) |
|
|
|
|
}, |
|
|
|
|
onStop(e) { |
|
|
|
|
options.onStop?.(e) |
|
|
|
|
handler(state) |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}` |
✓ |
|
|
|
Functions
mounted(el: any, binding: any): void
Code
mounted(el, binding) {
if (typeof binding.value === 'function') {
const handler = binding.value
const state = useScroll(el, {
onScroll() {
handler(state)
},
onStop() {
handler(state)
},
})
}
else {
const [handler, options] = binding.value
const state = useScroll(el, {
...options,
onScroll(e) {
options.onScroll?.(e)
handler(state)
},
onStop(e) {
options.onStop?.(e)
handler(state)
},
})
}
}
- Parameters:
el: any
binding: any
- Return Type:
void
- Calls:
useScroll (from ./index)
handler
options.onScroll
options.onStop
Type Aliases
BindingValueFunction
type BindingValueFunction = (state: UseScrollReturn) => void;
BindingValueArray
type BindingValueArray = [BindingValueFunction, UseScrollOptions];