Skip to content

Commit a41359b

Browse files
author
xueyuan
committed
refactor(virtual-list): improve code consistency and readability
1 parent 4c0ce3e commit a41359b

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

packages/varlet-ui/src/virtual-list/VirtualList.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import { computed, defineComponent, onMounted, reactive, ref, toRefs, watch } from 'vue'
1616
import { call, toNumber } from '@varlet/shared'
1717
import { createNamespace } from '../utils/components'
18+
import { toSizeUnit } from '../utils/elements'
1819
import { props } from './props'
1920
2021
const { name, n, classes } = createNamespace('virtual-list')
@@ -77,7 +78,7 @@ export default defineComponent({
7778
const containerStyle = computed(() => {
7879
if (props.containerHeight) {
7980
return {
80-
height: typeof props.containerHeight === 'number' ? `${props.containerHeight}px` : props.containerHeight,
81+
height: toSizeUnit(props.containerHeight),
8182
}
8283
}
8384
return {}
@@ -127,7 +128,9 @@ export default defineComponent({
127128
if (!contentRef.value) {
128129
return
129130
}
130-
const nodes = Array.from(contentRef.value.childNodes).filter((node: Node) => node.nodeType === 1) as HTMLElement[]
131+
const nodes = Array.from(contentRef.value.childNodes).filter(
132+
(node: Node) => node.nodeType === Node.ELEMENT_NODE,
133+
) as HTMLElement[]
131134
nodes.forEach((node, index) => {
132135
const height = node.offsetHeight
133136
const pos = state.cachePositions[index + state.start]

0 commit comments

Comments
 (0)