diff --git a/packages/core/useVirtualList/component.ts b/packages/core/useVirtualList/component.ts index 158e6d2b558..c39f97af060 100644 --- a/packages/core/useVirtualList/component.ts +++ b/packages/core/useVirtualList/component.ts @@ -30,11 +30,12 @@ export const UseVirtualList = defineComponent({ 'options', 'height', ] as unknown as undefined, - setup(props, { slots }) { + setup(props, { slots, expose }) { const { list: listRef } = toRefs(props) - const { list, containerProps, wrapperProps } = useVirtualList(listRef, props.options) - + const { list, containerProps, wrapperProps, scrollTo } = useVirtualList(listRef, props.options) + expose({ scrollTo }) + typeof containerProps.style === 'object' && !Array.isArray(containerProps.style) && (containerProps.style.height = props.height || '300px') return () => h('div', diff --git a/packages/core/useVirtualList/index.md b/packages/core/useVirtualList/index.md index e96bb844c4d..c17626009c7 100644 --- a/packages/core/useVirtualList/index.md +++ b/packages/core/useVirtualList/index.md @@ -101,3 +101,5 @@ const { list, containerProps, wrapperProps } = useVirtualList( ``` + +To scroll to a specific element, the component exposes `scrollTo(index: number) => void`.